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