AJS - Closures and Scoping | Nov 27

Name:
Email:
What is the output of the following code?
 
let a = 7;
if(a === 7){
     let b = 4;
}else{
     let b = 5;
}
function x(){
     console.log(a)
     console.log(b)
     return;
}
x();
7
5
Error : a is not defined
7
Error : b is not defined
undefined
undefined
What should be returned in function x (in place of ?) to get the output as 10?

function x(){
    let a = 10;
    function y(){
        console.log(a);
        return;
    }
    return ?;
}
z = x();
z();
A
Y()
Y
Output 10 can never be achieved
What will be output of the below code?
 
let a = 2;
{
    let b = 3;
    console.log(a);
}
function x(){
    let c = 4;
    console.log(b);
    return;
}
console.log(c);
 
2
error : b is not defined
2
error: c is not defined
Error : a is not defined
2
4
What is closure?
Function objects
Scope where function’s variables are resolved
Both Function objects and Scope where function’s variables are resolved
Function return value
What is the output of the following code?
 
let a = 2;
{
    var b = 3;
    console.log(a)
}
console.log(b);
2
3
2
undefined
2
error : b is not defined
Reference error : a is not defined
What kind of scoping does JavaScript use?
Literal
Lexical
Segmental
Sequential
{"name":"AJS - Closures and Scoping | Nov 27", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"Name:, Email:, What is the output of the following code?   let a = 7;if(a === 7){      let b = 4;}else{     let b = 5;}function x(){     console.log(a)     console.log(b)     return;}x();","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}
Powered by: Quiz Maker