JavaScript code quiz questions and answers

JavaScript code quiz questions and answers

What will happen when the following code is executed?

var x = 5;
console.log(x);
if (true) {
    var x = 6;
    console.log(x);
}
console.log(x);
//The Output will be -
5
6
6

What will happen when the following code is executed?
var x = 5;
console.log(x);
if (false) {
    var x = 6;
    console.log(x);
}
console.log(x);
//The Output will be -
5
5

What will happen when the following code is executed?
var x = 5;
function a() {
    var x = 6;
    return x;
}
console.log(x);
console.log(a());
//The Output will be -
5
6

What will happen when the following code is executed?
var x = 5;
function a() {
    x = 6;
    return x;
}
console.log(x);
console.log(a());
//The Output will be -
5
6

What will happen when the following code is executed?
var x = 5;
function a() {
    let x = 6;
    return x;
}
console.log(x);
console.log(a());
//The Output will be -
5
6

What will happen when the following code is executed?
let x = 5;
function a() {
    let x = 6;
    return x;
}
console.log(x);
console.log(a());
//The Output will be -
5
6

What will happen when the following code is executed?
const x = 5;
function a() {
    let x = 6;
    return x;
}
console.log(x);
console.log(a());
//The Output will be -
Uncaught SyntaxError: Identifier 'x' has already been declared
at<anonymous>: 1: 1

What will happen when the following code is executed?
const x = 5;
function a() {
    x = 6;
    return x;
}
console.log(x);
console.log(a());
//The Output will be -
Uncaught SyntaxError: Identifier 'x' has already been declared
at<anonymous>: 1: 1

What will happen when the following code is executed?
const x = 5;
function a() {
    const x = 6;
    return x;
}
console.log(x);
console.log(a());
//The Output will be -
Uncaught SyntaxError: Identifier 'x' has already been declared
at<anonymous>: 1: 1

What will happen when the following code is executed?
const x = 5;
function a() {
    var x = 6;
    return x;
}
console.log(x);
console.log(a());
//The Output will be -
Uncaught SyntaxError: Identifier 'x' has already been declared
at<anonymous>: 1: 1

What will happen when the following code is executed?
var x = 5;
function a() {
    const x = 6;
    return x;
}
console.log(x);
console.log(a());
//The Output will be -
5
6

What will happen when the following code is executed?
let x = 5;
function a() {
    var x = 6;
    return x;
}
console.log(x);
console.log(a());
//The Output will be -
Uncaught SyntaxError: Identifier 'x' has already been declared
at<anonymous>: 1: 1

What will happen when the following code is executed?
var x = 5;
function a() {
    var x = 6;
    return x;
}
x;
a();
//The Output will be -
6

What will happen when the following code is executed?
var x = 5;
function a() {
    var x = 6;
    return x;
}
x = a();
//The Output will be -
6

What will happen when the following code is executed?
var x = 5;
function a() {s
    var x = 6;
    return x;
}
x
//The Output will be -
5

What will happen when the following code is executed?
var x = 5;
function a() {
    var x = 6;
    return x;
}
console.log(x);
console.log(a());
//The Output will be -
5
6

What will happen when the following code is executed?
var x = 5;
function a() {
    var x = 6;
}
console.log(x);
console.log(a());
//The Output will be -
5

What will happen when the following code is executed?
var x = 5;
function a() {
    let x = 6; return x;
}
console.log(x);
console.log(a());
//The Output will be -
5
6

ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

JavaScript code quiz questions and answers JavaScript code quiz questions and answers Reviewed by Anil Singh on 7:44 AM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^