What is a JavaScript boolean?
A data type representing a truth value: true or false.
Give an example of a use case for booleans.
Conditional logic (e.g., if statements), flags/switches, comparisons in loops.
How do you declare a boolean variable in JavaScript?
let isLoggedIn = true; or let isAdult = false.
What are the ‘falsy’ values in JavaScript?
0, “” (empty string), null, undefined, NaN.
What is a JavaScript object?
A collection of properties, where each property has a key (name) and a value.
Give an example of a use case for objects.
Representing real-world entities (users, products), storing configurations, organizing code.
How do you create an object in JavaScript?
Using curly braces {}: let person = { name: “Alice”, age: 30 };
How do you access a property in an object using dot notation?
objectName.propertyName (e.g., person.name).
How do you access a property in an object using bracket notation?
objectName[“propertyName”] (e.g., person[“age”]) - Useful for variable keys.
What is a method in an object?
A function defined as a property of an object. It can be called using object.methodName().
What does this refer to inside an object’s method?
The object itself.
How do you add a new property to an existing object?
objectName.newProperty = value.
How do you delete a property from an object?
delete objectName.propertyName.
What is a JavaScript array?
An ordered list of values.
Give an example of a use case for arrays.
Storing lists of items, representing collections of data, performing operations on sequences.
How do you create an array in JavaScript?
Using square brackets []: let colors = [“red”, “green”, “blue”];
How do you access an element in an array?
Using its index (starting from 0): arrayName[index] (e.g., colors[0]).
How do you find the number of elements in an array?
Using the length property: arrayName.length.
Name three common array methods for adding/removing elements.
push() (add to end), pop() (remove from end), shift() (remove from beginning), unshift() (add to beginning).
Explain the difference between slice() and splice() array methods.
slice() creates a new array containing a portion of the original. splice() modifies the original array by removing or replacing elements.