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