JavaScript Worksheet: Basics
Code tip (Line by line): let x = 5; makes a variable x holding 5; x = x + 2; changes it to 7. console.log(…) writes in the console; alert(…) shows a pop-up box. Text in quotes + anything = joined text: "5" + 3 → "53".
NameDateTime takenScore ___ / 40
-
1.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 9;
console.log(x + y); (a) 59 (b) Error (c) 14 -
2.⚡ What number does this code print?
let marks = 17;
marks = marks + 2;
marks = marks - 11;
console.log(marks); - 3.⚡ Which JavaScript word makes a new variable? (a) for (b) console.log() (c) let (d) if
- 4.⚡ Which JavaScript word runs code when true? (a) console.log() (b) let (c) alert() (d) if
- 5.⚡ Which JavaScript word repeats code? (a) if (b) let (c) for (d) alert()
-
6.⚡ What does this code show?
let name = "Meera";
alert("Hello, " + name + "!"); (a) Hello, name! (b) Meera (c) Hello, Meera! (d) name -
7.⚡ What number does this code print?
let a = 22;
let b = 35;
console.log(a + b); -
8.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 9;
console.log(x + y); (a) Error (b) 10 (c) 19 -
9.⚡ What number does this code print?
let a = 5;
let b = 4;
console.log(a * b); -
10.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 7;
console.log(x + y); (a) Error (b) 37 (c) 10 - 11.⚡ Where does console.log() show its output? (a) on the printer (b) on the title bar (c) in the console (d) in the address bar
-
12.⚡ What number does this code print?
let marks = 5;
marks = marks + 14;
marks = marks - 16;
console.log(marks); -
13.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 9;
console.log(x + y); (a) Error (b) 11 (c) 29 -
14.⚡ What does this code show?
let name = "Arjun";
console.log("Well done, " + name + "!"); (a) Well done, Arjun! (b) Well done, name! (c) Arjun (d) name -
15.⚡ What does this code show?
let name = "Riya";
alert("Welcome, " + name + "!"); (a) Riya (b) Welcome, Riya! (c) name (d) Welcome, name! - 16.⚡ Which word makes a new variable? (a) make (b) let (c) put (d) give
-
17.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 1;
console.log(x + y); (a) 4 (b) 31 (c) Error -
18.⚡ What number does this code print?
let apples = 16;
apples = apples + 4;
apples = apples - 2;
console.log(apples); -
19.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 7;
console.log(x + y); (a) 16 (b) Error (c) 97 -
20.⚡ What number does this code print?
let a = 55;
let b = 32;
console.log(a + b); - 21.⚡ Which JavaScript word writes in the console? (a) for (b) console.log() (c) let (d) if
- 22.⚡ Which tag holds JavaScript in a page? (a) <code> (b) <script> (c) <style> (d) <js>
-
23.⚡ What number does this code print?
let a = 2;
let b = 12;
console.log(a * b); - 24.⚡ A JavaScript file usually ends with which extension? (a) .js (b) .html (c) .jpg (d) .css
-
25.⚡ What does this code show?
let name = "Meera";
console.log("Hi, " + name + "!"); (a) Hi, name! (b) Meera (c) Hi, Meera! (d) name -
26.⚡ What number does this code print?
let runs = 13;
runs = runs + 4;
runs = runs - 11;
console.log(runs); -
27.⚡ What number does this code print?
let a = 24;
let b = 25;
console.log(a + b); -
28.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 2;
console.log(x + y); (a) Error (b) 32 (c) 5 -
29.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 7;
console.log(x + y); (a) 87 (b) Error (c) 15 -
30.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 6;
console.log(x + y); (a) 12 (b) 66 (c) Error -
31.⚡ What number does this code print?
let a = 12;
let b = 11;
console.log(a * b); - 32.⚡ What does alert() show? (a) a table (b) a pop-up box (c) a new tab (d) a picture
-
33.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 9;
console.log(x + y); (a) Error (b) 39 (c) 12 -
34.⚡ What does this code show?
let name = "Kabir";
console.log("Hi, " + name + "!"); (a) Kabir (b) name (c) Hi, Kabir! (d) Hi, name! -
35.⚡ What does this code print? (Look at the quotes!)
let x = "4";
let y = 2;
console.log(x + y); (a) 6 (b) Error (c) 42 -
36.⚡ What does this code show?
let name = "Meera";
alert("Hi, " + name + "!"); (a) Hi, Meera! (b) name (c) Hi, name! (d) Meera -
37.⚡ What number does this code print?
let a = 39;
let b = 30;
console.log(a - b); -
38.⚡ What number does this code print?
let a = 56;
let b = 39;
console.log(a - b); -
39.⚡ What number does this code print?
let score = 7;
score = score + 16;
score = score - 13;
console.log(score); - 40.⚡ Which JavaScript word shows a pop-up box? (a) alert() (b) if (c) console.log() (d) for
Answer key
- 59
- 8
- let
- if
- for
- Hello, Meera!
- 57
- 19
- 20
- 37
- in the console
- 3
- 29
- Well done, Arjun!
- Welcome, Riya!
- let
- 31
- 18
- 97
- 87
- console.log()
- <script>
- 24
- .js
- Hi, Meera!
- 6
- 49
- 32
- 87
- 66
- 132
- a pop-up box
- 39
- Hi, Kabir!
- 42
- Hi, Meera!
- 9
- 17
- 10
- alert()
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids