Variables
Control Flow (if-else)
Loops, Arrays, and Objects
100

How can you check if a variable x is equal to 10 in JavaScript?

var, let, const

100

How can you check if a variable x is equal to 10 in JavaScript?

if (x === 10) { /* code */ }

100

What is the purpose of a for loop in JavaScript?

To repeatedly execute a block of code a specific number of times.

200

What is the scope of a variable declared with the let keyword?

Block scope

200

What is the purpose of the else statement in an if-else statement?

It provides an alternative code block to execute if the if condition is false.

200

How can you add an element to the end of an array in JavaScript?

push()

300

What will be the value of x after the following code: let x = 5; x = x + 3;?

8

300

How do you write an if statement that checks if a number is even?

if (num % 2 === 0) { /* code */ }

300

How do you access a property of an object in JavaScript?

You can use dot notation or bracket notation, like myObject.propertyName or myObject['propertyName'].

400

What is the difference between let, const, and var when declaring variables?

let and const have block scope, while var has function scope. const cannot be reassigned after declaration.

400

What is a ternary operator in JavaScript, and how does it work?

It's a shorthand for an if-else statement. It has the form condition ? expr1 : expr2. If the condition is true, expr1 is evaluated; otherwise, expr2 is evaluated.

400

Write a for loop that iterates through an array of numbers and calculates their sum.

var sum;

for(var = i; i < array.length; i++){

 sum += array[i];

}

500

What is the value of a variable that has not been initialized?

undefined

500

Explain the concept of "truthy" and "falsy" values in JavaScript.

In JavaScript, values are inherently "truthy" (e.g., numbers other than 0, non-empty strings, objects) or "falsy" (e.g., 0, empty string, null, undefined, false). These values determine the result of conditional statements.

500

Explain the difference between an array and an object in JavaScript.

An array is an ordered list of values, accessible by index, typically used for collections of similar items. An object is an unordered collection of key-value pairs, where keys are strings (or Symbols), and values can be of any data type, used for representing structured data