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