Tell us what’s happening:
I don’t understand scope and I need feedback abut why these different examples have local/global scope or if they throw a reference error or undefined. I am trying to understand what scope means so that I can correctly move with the right building blocks to the next tier of understanding, rather than learning sloppy fundamentals.
I have provided the answers but I dont understand what differentiatesd one from the other. This core issue is preventing me from completing the assignments on my own rather than getting spoon-fed answers. I know this is simple, but I think it’s pretty important ( I could be wrong).
I don’t understand what a reference error is or what undefined means and I think this is holding me back in my professional career.
Your code so far
-
function func() {
if (true) {
let a = ‘hello’;
}
console.log(a) -
The three choices of answers are:
a.‘hello’
b.undefined
c.Reference error - this is the answer -
function func() {
if (false) {
var a = ‘goodbye’;
}
console.log(a);
} -
The answer choices are:
a. undefined - this is the answer
b. reference error
c.‘goodbye’ -
function func() {
let a = ‘hello’;
if (true) { let a = ‘goodbye’;}
console.log(a);
} -
a. undefined
b. ‘goodbye’
c. ‘hello’ -this is the answer -
function func() {
var a = ‘hello’;
}
consle.log(a); -
a. ‘hello’
b. reference error - this is the answer
c. ‘goodbye’ - this is the answer -
function func() { let a =‘hello’;
if (true) {
let a = ‘goodbye’;
console.log(a);
}
} -
a. ‘hello’
b. ‘goodbye’ - this is the answer
c. undefined -
function func(){
if (true) {
var a = ‘hello’;
}
console.log(a);
} -
a. a
b. undefined
c. ‘hello’ - this is the answer
Your browser information:
Your Browser User Agent is: **Chrome/63.0.3239.84**
.
Link to the challenge:
https://www.enki.com/ (on the app, the different examples of scope are provided above if you complete the challenges on the app)