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 = "2";
let y = 2;
console.log(x + y); (a) Error (b) 4 (c) 22 -
2.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 4;
console.log(x + y); (a) 10 (b) Error (c) 64 - 3.⚡ What does alert() show? (a) a picture (b) a new tab (c) a pop-up box (d) a table
- 4.⚡ Where does console.log() show its output? (a) in the console (b) on the printer (c) in the address bar (d) on the title bar
- 5.⚡ Which JavaScript word writes in the console? (a) if (b) let (c) console.log() (d) alert()
- 6.⚡ Which JavaScript word repeats code? (a) let (b) if (c) console.log() (d) for
-
7.⚡ What number does this code print?
let marks = 26;
marks = marks + 16;
marks = marks - 35;
console.log(marks); -
8.⚡ What number does this code print?
let a = 22;
let b = 40;
console.log(a + b); -
9.⚡ What number does this code print?
let a = 54;
let b = 31;
console.log(a + b); -
10.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 6;
console.log(x + y); (a) Error (b) 96 (c) 15 -
11.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 8;
console.log(x + y); (a) 13 (b) Error (c) 58 - 12.⚡ Which word makes a new variable? (a) put (b) make (c) give (d) let
-
13.⚡ What does this code show?
let name = "Aman";
alert("Hi, " + name + "!"); (a) Aman (b) Hi, Aman! (c) name (d) Hi, name! -
14.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 4;
console.log(x + y); (a) Error (b) 13 (c) 94 -
15.⚡ What number does this code print?
let a = 21;
let b = 39;
console.log(a + b); -
16.⚡ What does this code show?
let name = "Kabir";
alert("Hi, " + name + "!"); (a) Hi, name! (b) Kabir (c) Hi, Kabir! (d) name -
17.⚡ What number does this code print?
let a = 4;
let b = 11;
console.log(a * b); - 18.⚡ Which tag holds JavaScript in a page? (a) <script> (b) <style> (c) <code> (d) <js>
-
19.⚡ What number does this code print?
let runs = 6;
runs = runs + 2;
runs = runs - 2;
console.log(runs); - 20.⚡ Which JavaScript word runs code when true? (a) if (b) for (c) alert() (d) console.log()
-
21.⚡ What does this code show?
let name = "Arjun";
alert("Welcome, " + name + "!"); (a) Welcome, name! (b) Arjun (c) Welcome, Arjun! (d) name -
22.⚡ What number does this code print?
let a = 6;
let b = 1;
console.log(a - b); -
23.⚡ What number does this code print?
let a = 12;
let b = 37;
console.log(a + b); -
24.⚡ What does this code print? (Look at the quotes!)
let x = "4";
let y = 6;
console.log(x + y); (a) Error (b) 10 (c) 46 -
25.⚡ What does this code print? (Look at the quotes!)
let x = "4";
let y = 2;
console.log(x + y); (a) 42 (b) Error (c) 6 - 26.⚡ Which JavaScript word makes a new variable? (a) alert() (b) console.log() (c) if (d) let
- 27.⚡ A JavaScript file usually ends with which extension? (a) .html (b) .css (c) .jpg (d) .js
-
28.⚡ What number does this code print?
let apples = 25;
apples = apples + 13;
apples = apples - 2;
console.log(apples); -
29.⚡ What number does this code print?
let a = 57;
let b = 5;
console.log(a + b); -
30.⚡ What number does this code print?
let a = 12;
let b = 8;
console.log(a * b); -
31.⚡ What does this code show?
let name = "Kabir";
console.log("Hi, " + name + "!"); (a) name (b) Hi, Kabir! (c) Kabir (d) Hi, name! -
32.⚡ What does this code show?
let name = "Riya";
console.log("Welcome, " + name + "!"); (a) Welcome, Riya! (b) name (c) Riya (d) Welcome, name! -
33.⚡ What does this code show?
let name = "Zoya";
console.log("Welcome, " + name + "!"); (a) Zoya (b) name (c) Welcome, Zoya! (d) Welcome, name! -
34.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 1;
console.log(x + y); (a) 6 (b) 51 (c) Error -
35.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 2;
console.log(x + y); (a) 62 (b) Error (c) 8 -
36.⚡ What does this code print? (Look at the quotes!)
let x = "7";
let y = 2;
console.log(x + y); (a) 9 (b) Error (c) 72 -
37.⚡ What number does this code print?
let a = 20;
let b = 5;
console.log(a + b); -
38.⚡ What number does this code print?
let a = 39;
let b = 7;
console.log(a + b); -
39.⚡ What number does this code print?
let a = 23;
let b = 24;
console.log(a + b); -
40.⚡ What number does this code print?
let a = 12;
let b = 8;
console.log(a - b);
Answer key
- 22
- 64
- a pop-up box
- in the console
- console.log()
- for
- 7
- 62
- 85
- 96
- 58
- let
- Hi, Aman!
- 94
- 60
- Hi, Kabir!
- 44
- <script>
- 6
- if
- Welcome, Arjun!
- 5
- 49
- 46
- 42
- let
- .js
- 36
- 62
- 96
- Hi, Kabir!
- Welcome, Riya!
- Welcome, Zoya!
- 51
- 62
- 72
- 25
- 46
- 47
- 4
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids