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