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