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