What keyword is used to declare a variable in JavaScript?
var, let, or const.
What keyword is used to create a conditional statement in JavaScript?
if
What is the purpose of a for loop in JavaScript?
A for loop is used for iterating over a sequence (such as an array) with a predetermined number of iterations.
How do you create an empty array in JavaScript?
var emptyArray = [];
How to create an object?
var object = {};
What is the difference between let, const, and var when declaring variables?
var has function-level scope (global), while let and const have block-level scope (local). const cannot be reassigned, but let and var can.
What happens when an If statements conditional is not true?
Nothing happens
How does a while loop differ from a for loop?
A while loop continues executing as long as a specified condition is true, whereas a for loop is typically used for a fixed number of iterations
How can you access the third element in an array using its index?
array[2]
What is an object in JavaScript?
An object is a collection of key-value pairs where keys are strings (or symbols) and values can be of any data type.
What is the value of a variable without declaring its value?
undefined
What is the difference between == and === in JavaScript?
== is equal operator but === strictly equal operator
When might you use a do-while loop instead of a while or for loop?
You might use a do-while loop when you want to ensure that the loop code block runs at least once, regardless of the condition
How can you add an element to the end of an array in JavaScript?
push()
How do you add a new property to an existing object in JavaScript?
myObject.newProperty = "new value";
myObject["newProperty"] = "new value";
How will you declare a variable in JavaScript that stores the string Tom?
var name = 'Tom';
How do you write an if statement that checks if a number is even?
if (num % 2 === 0)
Explain the purpose of the break and continue statements in loops
break is used to exit a loop prematurely, while continue is used to skip the current iteration and continue to the next one
What keyword is used to iterate through an array?
array.length
What values can be stored in an object?
All data types (strings, numbers, arrays, functions, objects)
What is the value of a variable that has not been initialized?
undefined.
Explain the concept of a ternary operator in JavaScript and provide an example
The ternary operator (? :) is a shorthand for writing if-else statements. Example: let result = (condition) ? "True" : "False";
Write a for loop that iterates from 1 to 10 and prints the square of each number
for (var i = 1; i <= 10; i++)
{ console.log(i * i); }
What is the use of an array?
Collection of variables, it is used to group related values into one variable.
What is the difference of objects and arrays?
An object is a key-value pair, and the array are index based.