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