JavaScript/Self Test


Category:Book:JavaScript#Self%20Test%20

You can test yourself by answering the following questions. When in doubt, you should undertake a test in your development environment (editor, IDE, browser). So it's also a test of whether you have installed all the necessary tools to execute the examples of the Wikibook.

Introduction

1

Inside which HTML element do you put the JavaScript code?

<javascript>
<source>
<script>
<scripting>
None of the above.

2

Does this sequence of statements lead to an error?
let x = 0;
x = 1;
x = 'one';

Yes
No

Syntax and Semantic

1

Is there a syntax error?
let x = 1:

Yes
No

2

Is there a syntax error?
let x = 1;
let y = 2;
x+y = 3;

Yes
No

3

Which line contains a syntax error?
/* 1 */ let x = 1;
/* 2 */ let y = 1;
/* 3 */ let x = 1, y = 1;
/* 4 */ let x, y = 1;

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

4

Which lines contain a syntax error?
/* 1 */ let firstName_1 = "Michael";
/* 2 */ let firstName_2 = 'Michael';
/* 3 */ let firstName_4 = 'Mikhaïl';
/* 4 */ let firstName_5 = "Михаил";

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

5

Which line leads to an error message?
/* 1 */ let x = 1;
/* 2 */ const y = 2;
/* 3 */ x = 3;
/* 4 */ y = 4;

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

6

Which line leads to an error message?
/* 1 */ let x = 1;
/* 2 */ x = 2 + 3(4 + 5);
/* 3 */ x = 3;
/* 4 */ x = -x;

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

7

Which line(s) leads to an error message?
/* 1 */ let x = [1, 2];
/* 2 */ let x = [[1], [2]];
/* 3 */ let x = [[1, 2], [3, 4]];
/* 4 */ let x = [[[1], [2]], [[3], [4]]];
/* 5 */ let x = [1], [2];
/* 6 */ let x = [1, '2'];

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

8

Is there a syntax error?
"use strict";
let persons = ['Alice', 'Bert', 'Caesar'];
for (let i = 0, i < persons.length, i++) {
  alert(persons[i]);
} //

Yes
No

9

Which line contains a syntax error?
/* 1 */ alert("1 + 2 = " + 3);
/* 2 */ alert("1 + 2 = " + "3");
/* 3 */ alert("1 + 2 = " 3)
/* 4 */ alert(1 + 2 == 3)

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

Type Conversion

1

Which message(s) will not be shown?
let x = 1, y = 2, z = '2';
alert(x + y);
alert(x + z);
alert(x - z);

3
12
-1
All will be shown.

2

What message(s) will not be shown?
let x = 1;
alert(x);
alert(x = 5);
alert(x == '5');
alert(x === 5);

Error Message
true
false
5
1

Loops

1

What will be the result in sum?
"use strict";
let sum = 0;
for (let i = 1; i < 5; i++) {
  sum = sum + i;
} //
alert(sum);
The result in sum will be

.

2

What will be the result in sum?
"use strict";
let sum = 0;
for (let i = 0; i < 5; i++) {
  for (let j = 10; j >= 0; j--) {
    if (i === j) {
      sum = sum + i - j + 1;
    } //
  } //
} //
alert(sum);
The result in sum will be

.

3

Is there a syntactical error?
"use strict";
let sum = 0;
for (let i = 0; i < 5; i++)
  for (let j = 10; j >= 0; j--) {
    if (i === j) {
      sum = sum + i - j + 1;
    } //
  } //
} //
alert(sum);

Yes
No

4

What will be the result?
"use strict";
let sum = 0;
for (let i = 0; i = 3; i++) {
  sum = sum + i;
} //
alert(sum);

0
6
Infinite loop
None of the above

Category:Book:JavaScript Category:Pages using the JsonConfig extension