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