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