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