1) Look at a semicolon
Without semicolon(s), a Java program cannot be compiled.
(That is if there are statements; an empty Java program or a Java program with only empty classes doesn't need any semicolons)
I think I've told this story before, but at a meeting for CS education leaders they organized a panel of high school kids taking CS classes, and someone asked them "What's been your biggest problem in learning programming?" And one after another, all four of them said "semicolons"! Made me proud.
I keep forgetting that.
JavaScript source code without a semicolon:
(new Function(`
console.log("Hello, world!")\u003b
switch(3) {
case(3): alert("three")\u003b break\u003b
default: console.log(null)\u003b break\u003b
}
`))()
groan
\x3b is a semicolon
You don't actually need semicolons at the end of lines in JavaScript unless the next line begins with an open bracket
I used to write JavaScript without semicolons except for putting multiple statements on the same line, but when I learned Java in my AP CS A course, I have been putting semicolons at the ends of my lines in JavaScript as well.
You're welcome.
I don't know why this is flagged
It's too short.
Actually,\u003b IS a semicolon! The Function object changes all characters in a string that has a reverse soildus to something else.
- \n means new line character
- \a means ring the bell
- \u means unicode digits
- \r means carrige return
- \f means form feed
- \\ means nothing but that old dull reverse solidus
- \/ means solidus
- \t means tab character
The actual source code does not have a semicolon.
I used the Function constructor and escaped semicolons (without using literal semicolons).
Crafty....
There is a "special" controll character,\a,to ring the bell like \u0007
For some reason, I like that control character, which in some places can be represented with ^G
. In my programming language enilKode, if you use it in the pop
, ask
, or yon
*, or print
functions, a bell sound should play (except for the fact that an interpreter hasn't been written yet).
*It stands for "yes or no", but I might change the name
"a" for "alert."
Oh,no wonder it's not \b(meanwhile occupied by \u0008)
In enilKode, it is escaped with 'b
in a text string.