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