JavaScript/Lexical structure/Exercises

From Wikibooks, open books for an open world
Jump to navigation Jump to search

1 Which line(s) lead to a syntax error?

/* 1 */ "use strict;"
/* 2 */ let a = 0
/* 3 */ let b = 0 //;
/* 4 */ let
/* 5 */ c = 0;

Line 1
Line 2
Line 3
Line 4
Line 5
None of the above

2 Which line(s) lead to a syntax error?

/* 1 */ "use strict;"
/* 2 */ let personName = "Hagar den skrækkelige";
/* 3 */ let Hägar = "Hägar the Horrible";
/* 4 */ let ä = "Hägar the Horrible";
/* 5 */ let Hägar = "Hagar den skrækkelige";

Line 1
Line 2
Line 3
Line 4
Line 5
None of the above

3 Which line(s) lead to a syntax error?

/* 1 */ "use strict;"
/* 2 */ let isOpen = true // or "true" ??? or TRUE ???
/* 3 */ isOpen = 5;
/* 4 */ let _isOpen = false;
/* 5 */ isOpen = _isOpen

Line 1
Line 2
Line 3
Line 4
Line 5
None of the above

4 Which line(s) lead to a syntax error?

/* 1 */ "use strict;"
/* 2 */ let countFiles = 5;
/* 3 */ countFiles = countFiles + /* or is it minus?? */ 1;
/* 4 */ countFiles = CountFiles * 2;
/* 5 */ // const twoFiles = 10;
/* 6 */ // const 2Files = 10;

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
None of the above


Be creative
  1. Create a code snippet with 3 valid and 3 invalid variable declarations.
  2. Create a code snippet with extensive comments, e.g.: explain WHY you have used certain variable names, whether this snippet is part of a huge project, what the author's name is, when the snippet was created, ... .
  3. Create a code snippet and use non-Latin characters as variable names.