JS Fundamentals - Code Structure Flashcards

1
Q

Importance of semicolon

A

alert(“All fine now”);

[1, 2].forEach(alert)
Now we have the “All fine now” message followed by 1 and 2.

The error in the no-semicolon variant occurs because JavaScript does not assume a semicolon before square brackets […].

So, because the semicolon is not auto-inserted, the code in the first example is treated as a single statement. Here’s how the engine sees it:

alert(“There will be an error”)[1, 2].forEach(alert)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Comments

A

They don’t affect its execution because the engine simply ignores them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

One line comments

A

One-line comments start with two forward slash characters //.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Multi Line comments

A
/* An example with two messages.
This is a multiline comment.
*/
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

HotKeys

A

In most editors, a line of code can be commented out by pressing the Ctrl+/ hotkey for a single-line comment and something like Ctrl+Shift+/ – for multiline comments (select a piece of code and press the hotkey). For Mac, try Cmd instead of Ctrl and Option instead of Shift.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Nested comments are not supported

A

There may not be // inside another //.

Such code will die with an error:

/*
  /* nested comment ?!? */
*/
alert( 'World' );
How well did you know this?
1
Not at all
2
3
4
5
Perfectly