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