Skip to content

Instantly share code, notes, and snippets.

@csim
Last active August 27, 2020 16:43
Show Gist options
  • Save csim/2fb35099a926b66bc0072cece58ec73b to your computer and use it in GitHub Desktop.
Save csim/2fb35099a926b66bc0072cece58ec73b to your computer and use it in GitHub Desktop.
// Please name the data types available JavaScript.
console.log("---- Block 1 ---------------------------------------------");
try {
function function1() {
var x1 = 1;
console.log(typeof x1);
console.log(x1);
}
function1();
console.log(typeof x1);
console.log(x1);
} catch (e) {
console.error(e);
}
// What is printed to the console at this point?
console.log("---- Block 2 ---------------------------------------------");
try {
var x2;
function function2() {
x2 = 2;
console.log(typeof x2);
console.log(x2);
}
function2();
console.log(typeof x2);
console.log(x2);
} catch (e) {
console.error(e);
}
// What is printed to the console at this point?
console.log("---- Block 3 ---------------------------------------------");
try {
function function3() {
if (true) {
let x3 = 3;
console.log(typeof x3);
console.log(x3);
}
console.log(typeof x3);
console.log(x3);
}
function3();
console.log(typeof x3);
console.log(x3);
} catch (e) {
console.error(e);
}
// What is printed to the console at this point?
var x = 1;
console.log(x == 1);
console.log(x === 1);
console.log(x == "1");
console.log(x === "1");
// What is logged to the console?
var obj1 = {
function1: function() {
console.log(this);
console.log(typeof this);
console.log(this === obj1);
}
}
obj1.function1();
obj1.function1.call({ x1: 1 });
// What is logged to the console?
const arr = [10, 12, 15, 21];
for (var i = 0; i < arr.length - 1; i++) {
var timeout = setTimeout(function() {
console.log(`Index: ${i}, element: ${arr[i]}`);
}, 1000);
}
// What is logged to the console?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment