SCOPES Flashcards

1
Q

Do Global Scoops affect functions? will it’s value be changed if they are declared the same way?

A

No, it won’t, since functions separate their variables to a different scope therefore it does not affect the variables of the function.

//Globral Scope
var a = 1;
let b = 2;
const c = 3;
function test(){
var a = 4;
let b = 5;
const c = 6;
console.log('Function Scope: ', a, b, c);
}
test();

console.log(‘Global Scope ‘ , a, b, c);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Do Global Scoops affect If statements? will its value be changed if they are declared the same way?

A

Yes, it will, the global scope will take the new value assign into the if statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Do Global Scoops VAR affect Loops? will its value be changed if they are declared the same way?

A

Yes, it will, the global scope will change and the loop won’t be providing the correct number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can I loop through a document?

A
val = document.scripts;
val = document.scripts[2].getAttribute('src');

let scripts = document.scripts;

let scriptsArr = Array.from(scripts)

scriptsArr.forEach(function(script) {
console.log(script.getAttribute(‘src’));
});

console.log(val);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly