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