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