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