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