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