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