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 = 5;
console.log(x + y); (a) Error (b) 55 (c) 10 -
2.⚡ What number does this code print?
let marks = 8;
marks = marks + 13;
marks = marks - 4;
console.log(marks); - 3.⚡ Which tag holds JavaScript in a page? (a) <script> (b) <js> (c) <code> (d) <style>
-
4.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 8;
console.log(x + y); (a) 88 (b) 16 (c) Error - 5.⚡ Which JavaScript word runs code when true? (a) console.log() (b) alert() (c) if (d) let
-
6.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 9;
console.log(x + y); (a) Error (b) 12 (c) 39 -
7.⚡ What number does this code print?
let a = 6;
let b = 4;
console.log(a * b); -
8.⚡ What does this code print? (Look at the quotes!)
let x = "4";
let y = 3;
console.log(x + y); (a) 43 (b) 7 (c) Error -
9.⚡ What number does this code print?
let a = 46;
let b = 1;
console.log(a + b); -
10.⚡ What number does this code print?
let coins = 21;
coins = coins + 6;
coins = coins - 8;
console.log(coins); -
11.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 7;
console.log(x + y); (a) Error (b) 9 (c) 27 - 12.⚡ Which JavaScript word writes in the console? (a) for (b) if (c) console.log() (d) alert()
- 13.⚡ What does alert() show? (a) a pop-up box (b) a picture (c) a new tab (d) a table
-
14.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 3;
console.log(x + y); (a) 5 (b) Error (c) 23 -
15.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 4;
console.log(x + y); (a) Error (b) 10 (c) 64 -
16.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 4;
console.log(x + y); (a) Error (b) 14 (c) 5 -
17.⚡ What does this code show?
let name = "Riya";
console.log("Hi, " + name + "!"); (a) Hi, name! (b) Hi, Riya! (c) Riya (d) name -
18.⚡ What number does this code print?
let a = 58;
let b = 20;
console.log(a + b); - 19.⚡ What does JavaScript add to a web page? (a) the domain name (b) the page title (c) actions and changes (d) only colours
-
20.⚡ What number does this code print?
let a = 30;
let b = 28;
console.log(a - b); -
21.⚡ What does this code show?
let name = "Aman";
alert("Well done, " + name + "!"); (a) name (b) Well done, name! (c) Well done, Aman! (d) Aman - 22.⚡ Which JavaScript word shows a pop-up box? (a) alert() (b) let (c) console.log() (d) for
-
23.⚡ What number does this code print?
let a = 26;
let b = 25;
console.log(a - b); -
24.⚡ What does this code show?
let name = "Meera";
console.log("Hello, " + name + "!"); (a) Hello, name! (b) Hello, Meera! (c) name (d) Meera -
25.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 2;
console.log(x + y); (a) Error (b) 3 (c) 12 - 26.⚡ Which JavaScript word makes a new variable? (a) console.log() (b) let (c) alert() (d) if
- 27.⚡ A JavaScript file usually ends with which extension? (a) .jpg (b) .html (c) .css (d) .js
-
28.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 4;
console.log(x + y); (a) 9 (b) 54 (c) Error -
29.⚡ What number does this code print?
let apples = 22;
apples = apples + 10;
apples = apples - 28;
console.log(apples); -
30.⚡ What does this code show?
let name = "Aman";
alert("Welcome, " + name + "!"); (a) name (b) Aman (c) Welcome, name! (d) Welcome, Aman! -
31.⚡ What number does this code print?
let a = 53;
let b = 13;
console.log(a + b); -
32.⚡ 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 -
33.⚡ What does this code show?
let name = "Riya";
console.log("Hello, " + name + "!"); (a) Hello, name! (b) Hello, Riya! (c) name (d) Riya -
34.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 6;
console.log(x + y); (a) 36 (b) 9 (c) Error - 35.⚡ Which JavaScript word repeats code? (a) if (b) console.log() (c) let (d) for
-
36.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 3;
console.log(x + y); (a) 33 (b) Error (c) 6 -
37.⚡ What number does this code print?
let a = 2;
let b = 5;
console.log(a * b); -
38.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 1;
console.log(x + y); (a) Error (b) 4 (c) 31 -
39.⚡ What does this code show?
let name = "Zoya";
console.log("Hi, " + name + "!"); (a) Zoya (b) Hi, name! (c) name (d) Hi, Zoya! -
40.⚡ What number does this code print?
let a = 38;
let b = 1;
console.log(a + b);
Answer key
- 55
- 17
- <script>
- 88
- if
- 39
- 24
- 43
- 47
- 19
- 27
- console.log()
- a pop-up box
- 23
- 64
- 14
- Hi, Riya!
- 78
- actions and changes
- 2
- Well done, Aman!
- alert()
- 1
- Hello, Meera!
- 12
- let
- .js
- 54
- 4
- Welcome, Aman!
- 66
- 42
- Hello, Riya!
- 36
- for
- 33
- 10
- 31
- Hi, Zoya!
- 39
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids