JavaScript Interview

Objects, Arrays & Core Data Handling

JavaScript interview questions covering objects, properties, object methods, copying, arrays, collection methods, iteration, Map, Set and core data handling.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
26
JuniorBeginner

What is an object in JavaScript?

An object is a collection of key-value pairs used to represent related data and behavior. Property keys are strings or symbols, while values can be any JavaScript value, including functions and other objects.

27
JuniorBeginner

How can you create objects in JavaScript?

The most common approach is an object literal using braces. Objects can also be created with constructor functions, classes, Object.create, or the Object constructor.

28
JuniorBeginner

What is the difference between dot notation and bracket notation?

Dot notation accesses a property with a fixed valid identifier, such as user.name. Bracket notation accepts an expression and is required when the property name is dynamic, contains characters that are invalid in an identifier, or is stored in a variable.

29
JuniorBeginner

How do you add, update, and delete object properties?

JavaScript objects are dynamic by default. A property can be added or updated by assigning to it with dot or bracket notation. The delete operator removes an own property when the property is configurable.

30
JuniorBeginner

What are object methods in JavaScript?

An object method is a function stored as an object property. Method shorthand allows the function keyword to be omitted inside an object literal.

31
JuniorBeginner

What does the this keyword mean inside an object method?

For a regular function invoked as obj.method(), this normally refers to obj. However, this is not permanently attached to the function; its value depends on how the function is called.

32
JuniorBeginner

What is Object.keys()?

Object.keys returns an array containing the object's own enumerable string-keyed property names. It does not include inherited properties or symbol keys.

33
JuniorBeginner

What are Object.values() and Object.entries()?

Object.values returns an array of an object's own enumerable string-keyed property values. Object.entries returns an array of [key, value] pairs for those properties.

34
JuniorBeginner

What is Object.assign()?

Object.assign copies enumerable own properties from one or more source objects to a target object and returns the target. Later sources overwrite earlier properties with the same key.

35
JuniorBeginner

What is a shallow copy, and how is it different from a deep copy?

A shallow copy creates a new top-level object or array but keeps references to nested objects. Therefore, modifying a nested object through the copy can also affect the original.

36
JuniorBeginner

What does Object.freeze() do?

Object.freeze prevents adding, deleting, or changing the object's own properties and makes those properties non-configurable. In strict mode, invalid mutation attempts can throw errors.

37
JuniorBeginner

What is an array in JavaScript?

An array is an ordered, zero-indexed collection designed to store multiple values. JavaScript arrays are objects with special behavior for integer-like indexes and a length property.

38
JuniorBeginner

How can you check whether a value is an array?

Use Array.isArray(value). It reliably determines whether a value is an Array, including cases where typeof would only report "object".

39
JuniorBeginner

What is the difference between push(), pop(), shift(), and unshift()?

push adds one or more elements to the end of an array, while pop removes and returns the last element. unshift adds elements to the beginning, while shift removes and returns the first element.

40
JuniorBeginner

What is the difference between slice() and splice()?

slice returns a shallow copy of a selected portion of an array without modifying the original. splice changes the original array by removing, replacing, or inserting elements.

41
JuniorBeginner

What is the difference between map() and forEach()?

map executes a callback for each element and returns a new array containing the callback results. forEach executes a callback for each element but returns undefined.

42
JuniorBeginner

How does filter() work in JavaScript?

filter returns a new array containing only the elements for which the callback returns a truthy value. It does not modify the original array.

43
JuniorBeginner

What does reduce() do in JavaScript?

reduce processes an array and combines its elements into a single accumulated result. The result can be a number, string, object, array, map-like structure, or another value.

44
JuniorBeginner

What is the difference between find() and filter()?

find returns the first element that satisfies the callback, or undefined when no element matches. filter returns a new array containing every matching element.

45
JuniorBeginner

What is the difference between findIndex() and indexOf()?

indexOf searches for a specific value using strict equality and returns its index, or -1 when not found. findIndex accepts a callback and returns the index of the first element satisfying the condition.

46
JuniorBeginner

What is the difference between some() and every()?

some returns true when at least one array element satisfies the callback. every returns true only when all elements satisfy it.

47
JuniorBeginner

How does sort() work in JavaScript?

sort rearranges the original array in place. Without a compare function, elements are converted to strings and compared according to string ordering, which can produce unexpected results for numbers.

48
JuniorBeginner

What is the difference between for...of and for...in?

for...of iterates over values produced by an iterable such as an array, string, map, or set. for...in iterates over enumerable string property keys of an object, including inherited enumerable properties unless they are filtered.

49
JuniorBeginner

What are Map and Set in JavaScript?

Map is a key-value collection whose keys can be values of any type. Set is a collection of unique values. Both are iterable and provide dedicated methods such as set, get, has, add, and delete.

50
JuniorBeginner

What is the difference between Map and a plain object?

Both can represent key-value data, but Map accepts keys of any type, preserves insertion order for iteration, has a size property, and provides purpose-built methods such as get, set, has, and delete.