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