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