Which of the following is considered an object in Javascript?
MathWorks aptitude question, verified with a worked answer. Free to practise - no sign-up.
Which of the following is considered an object in Javascript?
Pick ONE OR MORE options
- ✓ A) function
Show answer & explanation
Answer: D. All of the above
In JavaScript, everything except primitives (numbers, strings, booleans, null, undefined, symbols) is an object. Arrays are objects (instances of Array), functions are objects (callable objects), and plain objects are the base object type. Therefore, all three are considered objects in JavaScript.
Step-by-step Derivation:
JavaScript's type system: typeof [] === 'object' (array is object), typeof function(){} === 'function' (but functions are objects too), typeof {} === 'object' (plain object). Since arrays, functions, and plain objects all inherit from Object.prototype and are reference types, they are all objects in JavaScript.