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