SCOPES Flashcards
Do Global Scoops affect functions? will it’s value be changed if they are declared the same way?
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);
Do Global Scoops affect If statements? will its value be changed if they are declared the same way?
Yes, it will, the global scope will take the new value assign into the if statement.
Do Global Scoops VAR affect Loops? will its value be changed if they are declared the same way?
Yes, it will, the global scope will change and the loop won’t be providing the correct number.
How can I loop through a document?
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);