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