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