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