Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1function greet() { let name = "Sam"; } | AWrong - name is scoped inside greet and isn't accessible outside it | |
| 2function calc() { let total = 10; return total; } | Blet count = 5; | |
| 3The area of code where a variable can be accessed | CDeclares name as a variable scoped inside greet | |
| 4Keeps a variable local so it can't be accessed outside its function | Dscope | |
| 5function greet() { let name = "Sam"; } console.log(name); | EDeclares total as a variable scoped inside calc | |
| 6function calc() { let total = 5; } console.log(total); | FWrong - total is scoped inside calc and isn't accessible outside it |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
scope — The area of code where a variable can be accessed; variables declared inside a function are local to it.function greet() {
let name = "Sam";
console.log(name);
}function calc() {
let total = 10;
return total;
}
console.log(calc());function show() {
let count = 5;
console.log(count);
}function test() {
if (true) {
let x = 1;
console.log(x);
}
}function calcArea(side) {
let area = side * side;
return area;
}
console.log(calcArea(4));