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