Question 1
Which of the following correctly declares a constant variable PI
with the value 3.14 in JavaScript?
var PI = 3.14;
let PI = 3.14;
const PI = 3.14;
PI = 3.14;
Question 2
What exactly does "Execution Context" mean in JavaScript?
Code block for function declarations
Environment for executing JavaScript code
Global object in the browser
Special runtime variable
Question 3
What happens when variable shadowing occurs in JavaScript?
A local variable hides a global variable with the same name
A function is unable to access global variables
Variables are reset to default values
JavaScript automatically changes the value of the variable.
Question 4
What will be the output of the following JavaScript code snippet?
let y = 30;
if (true) {
let y = 40;
console.log(y);
}
console.log(y);
30 40
40 30
40 40
SyntaxError
Question 5
What will be the output of this JavaScript code?
let a = 5;
function test() {
let a = 10;
console.log(a);
}
test();
console.log(a);
5 and 10
10 and 10
5 and 5
10 and 5
Question 6
What will happen when this code runs?
<html>
<body>
<script>
let userName = prompt("Enter your name:");
alert("Your name is: " + userName);
</script>
</body>
</html>
A pop-up displays "Your name is: [user's input]"
The name is printed in the browser console
The webpage content is updated with "Your name is: [user's input]"
No output
Question 7
Which of the following is true about the let keyword?
It is function-scoped
It is block-scoped and cannot be redeclared in the same scope
It can be redeclared within the same scope
It is hoisted to the top like var
Question 8
What will happen when this code is executed?
function greet(name) {
return "Hello, " + name;
}
console.log(greet("Alisha"));
The function will greet the name "Alisha"
The code will result in an error
"Hello, Alisha" will be logged in the console
Nothing will be logged
Question 9
Consider the const
declaration for an array:
const arr = [10, 20, 30];
arr[1] = 25;
console.log(arr);
What will be the output of the console.log(arr)
statement?
[10, 20, 30]
[10, 25, 30]
TypeError: Assignment to constant variable.
[1, 2, 3]
Question 10
JavaScript is a single-threaded language. What does that mean?
It can execute multiple tasks at once
It can only execute one task at a time
It doesn’t need any external libraries
It runs in multiple browsers simultaneously.
There are 10 questions to complete.