Strings in JavaScript represent sequences of UTF-16 code units used to store and manipulate textual data. Declared using single quotes, double quotes, or ES6 template literals (backticks), strings are primitive values and strictly immutable meaning methods do not mutate the original string in place but instead return a new string reference. JavaScript provides a rich set of built-in prototype methods for searching (indexOf, includes), extracting (slice, substring), modifying (replace, replaceAll, toLowerCase), and converting (split). Understanding indexing, string immutability, UTF-16 encoding details, and regex integration is vital for manipulating user inputs and passing technical code evaluations.
JavaScript Strings MCQs
1 min read
Correct Answer: b) object
Explanation:
In JavaScript, arrays are non-primitive object types. The typeof operator returns 'object' for array instances.
Correct Answer: a) Array.isArray()
Explanation:
Array.isArray() is the standard reliable static method used to verify if a variable is an Array.
Correct Answer: b) 1,2,34,5,6
Explanation:
Using the '+' operator on arrays coerces both arrays to strings ('1,2,3' and '4,5,6') and concatenates them into '1,2,34,5,6'.
Correct Answer: a) true
Explanation:
![] coerces to boolean false. Loose equality [] == false coerces [] to '' (0) and false to 0, yielding 0 == 0 which is true.
Correct Answer: b) false
Explanation:
Strict equality checks both type and reference. An empty array reference is not strictly equal to the primitive boolean false.
Correct Answer: b) false
Explanation:
Floating-point precision issues cause 0.1 + 0.2 to evaluate to 0.30000000000000004, which does not strictly equal 0.3.
Correct Answer: b) shift()
Explanation:
shift() removes the first element from an array and shifts all subsequent elements down by one index.
Correct Answer: b) unshift()
Explanation:
unshift() adds new items to the start of an array and returns the updated array length.
Correct Answer: b) 4
Explanation:
The push() method mutates the array and returns the new length of the modified array (which is 4).
Correct Answer: a) 1
Explanation:
shift() removes and returns the first element of the array, which is 1.
Correct Answer: b) undefined
Explanation:
Calling pop() on an empty array leaves the array unchanged and returns undefined.
Correct Answer: a) [2, 3]
Explanation:
splice(start, deleteCount) removes deleteCount elements from start index. Starting at index 1, it removes 2 items: [2, 3].
Correct Answer: a) [1, 4]
Explanation:
splice() mutates the target array in place. Removing index 1 and 2 leaves [1, 4].
Correct Answer: b) slice() returns a shallow copy without mutating the original array; splice() mutates the original array.
Explanation:
slice() is non-mutating and extracts a section into a new array. splice() modifies the existing array in place.
Correct Answer: a) [30, 40]
Explanation:
Negative start indices in slice() count back from the end of the array. Index -2 extracts the last 2 elements: [30, 40].
Correct Answer: b) Sorts elements as strings according to UTF-16 code units.
Explanation:
Without a comparator, sort() converts elements to strings and compares their UTF-16 code unit sequences.
Correct Answer: b) [1, 10, 2, 25]
Explanation:
Default lexicographical string sorting compares '10' before '2' because string character '1' comes before '2'.
Correct Answer: a) arr.sort((a, b) => a - b)
Explanation:
Providing comparator `(a, b) => a - b` returns negative when a < b, correctly ordering numbers numerically.
Correct Answer: b) reverse()
Explanation:
reverse() mutates the array in place and returns the reference to the same inverted array.
Correct Answer: a) toReversed()
Explanation:
ES2023 introduced toReversed() to return a reversed copy of an array without mutating the original.
Correct Answer: a) toSorted()
Explanation:
toSorted() returns a new sorted copy of an array, keeping the original array intact.
Correct Answer: a) [1, 2, 3, 4, 5]
Explanation:
concat() merges two or more arrays into a single new array.
Correct Answer: a) [1, 2, [3]]
Explanation:
flat(depth) flattens sub-array structures up to specified depth. Depth 1 flattens outer array to [1, 2, [3]].
Correct Answer: a) [1, 2, 3]
Explanation:
Passing Infinity to flat() recursively flattens nested arrays of any arbitrary depth.
Correct Answer: a) -1
Explanation:
indexOf() returns the first index at which a given element is found, or -1 if it is not present.
Correct Answer: a) true
Explanation:
Unlike indexOf() (which uses strict equality and fails on NaN), includes() uses SameValueZero algorithm and correctly finds NaN.
Correct Answer: a) -1
Explanation:
indexOf uses strict comparison (===). Since NaN === NaN is false, indexOf fails to locate NaN and returns -1.
Correct Answer: a) 20
Explanation:
find() returns the value of the FIRST element in the array that satisfies the provided testing function.
Correct Answer: a) 1
Explanation:
findIndex() returns the index position of the FIRST element that passes the predicate function. Value 20 is at index 1.
Correct Answer: a) 30
Explanation:
findLast() iterates the array in reverse order and returns the value of the first matching element (30).
Correct Answer: a) true
Explanation:
every() checks if ALL elements in the array pass the test condition. Since 1, 2, 3 are all > 0, it returns true.
Correct Answer: a) true
Explanation:
some() checks if AT LEAST ONE element in the array passes the condition. Element 3 is > 2, so it returns true.
Correct Answer: a) true
Explanation:
every() called on an empty array returns true for any condition (vacuous truth).
Correct Answer: a) false
Explanation:
some() called on an empty array returns false for any condition.
Correct Answer: a) "1-2-3"
Explanation:
join(separator) concatenates all array elements into a string separated by the specified separator string.
Correct Answer: a) "," (comma)
Explanation:
If no separator is provided, join() defaults to using a comma (",").
Correct Answer: a) 6
Explanation:
reduce accumulates products: initial 1 * 1 = 1; * 2 = 2; * 3 = 6.
Correct Answer: a) TypeError: Reduce of empty array with no initial value
Explanation:
Calling reduce() on an empty array without an initial value throws a TypeError.
Correct Answer: a) "321"
Explanation:
reduceRight processes array elements from right to left (last element to first), producing "321".
Correct Answer: a) ["f", "o", "o"]
Explanation:
Array.from creates a new array instance from an iterable object, splitting string 'foo' into characters.
Correct Answer: a) [2, 4, 6]
Explanation:
Array.from accepts an optional map function as its second argument to transform elements during array creation.
Correct Answer: a) Array.of(7) yields [7]; new Array(7) yields array with 7 empty slots.
Explanation:
Array.of(7) creates array containing item [7]. single numeric argument to Array constructor creates empty array of length 7.
Correct Answer: a) An array in which elements are non-contiguous and contain empty slots (holes).
Explanation:
Sparse arrays contain empty slots (indices with no values assigned), where array length exceeds actual element count.
Correct Answer: a) 11
Explanation:
Assigning to index 10 sets length to index + 1 = 11, creating indices 0-9 as empty slots.
Correct Answer: a) []
Explanation:
Object.keys ignores sparse array empty slots (holes) and returns an empty array.
Correct Answer: a) It skips unassigned empty slots entirely.
Explanation:
Built-in array iteration methods like forEach, map, filter skip unassigned indices in sparse arrays.
Correct Answer: a) It iterates over empty slots yielding `undefined` for each.
Explanation:
The for...of loop relies on array iterator, treating empty holes as elements with value `undefined`.
Correct Answer: a) [1]
Explanation:
Setting array length property to a smaller number truncates the array in place, deleting trailing elements.
Correct Answer: a) []
Explanation:
Setting length to 0 completely clears all elements from the array in place.
Correct Answer: a) RangeError: Invalid array length
Explanation:
Setting array length to a negative number or non-integer throws a RangeError.
Correct Answer: a) Deletes value at index 1 leaving an empty slot hole; array length remains 3.
Explanation:
Deleting an array element via delete operator removes property value, creating a sparse slot without modifying array length.
Correct Answer: a) true
Explanation:
The 'in' operator checks if index key 1 exists as a property in the array object, returning true.
Correct Answer: a) false
Explanation:
Index 3 does not exist in an array of length 3 (indices 0, 1, 2), returning false.
Correct Answer: a) [1, 0, 0]
Explanation:
fill(value, start, end) changes array elements to static value from start index 1 up to end index 3.
Correct Answer: a) [4, 5, 3, 4, 5]
Explanation:
copyWithin(target, start, end) copies elements from index 3 to 5 ([4, 5]) to target position index 0.
Correct Answer: a) Object.create(proto)
Explanation:
Object.create(proto) creates a new object using the existing object passed as prototype.
Correct Answer: a) Object.create(null)
Explanation:
Object.create(null) creates an object with a null prototype chain, free from standard Object.prototype methods.
Correct Answer: a) undefined
Explanation:
Since Object.create(null) has no prototype, standard Object methods like toString are undefined.
Correct Answer: a) Object.assign()
Explanation:
Object.assign(target, ...sources) performs shallow copies of own enumerable properties into target.
Correct Answer: a) Shallow copy
Explanation:
Object.assign() only copies property references at the top level (shallow copy).
Correct Answer: a) structuredClone()
Explanation:
structuredClone() is a standard built-in global function for performing deep copies of data structures.
Correct Answer: a) TypeError: Converting circular structure to JSON
Explanation:
JSON.stringify throws a TypeError if it encounters objects with circular references.
Correct Answer: a) Yes, structuredClone handles circular references automatically.
Explanation:
The structured clone algorithm natively supports structures containing circular references.
Correct Answer: a) Object.values()
Explanation:
Object.values(obj) extracts property values of own enumerable string properties into an array.
Correct Answer: a) Object.fromEntries()
Explanation:
Object.fromEntries() performs inverse operation of Object.entries(), building object from key-value pairs.
Correct Answer: a) Returns true if specified object has indicated property as its own property.
Explanation:
Object.hasOwn() is the recommended ES2022 replacement for obj.hasOwnProperty().
Correct Answer: a) It works reliably on objects created with Object.create(null) and overridden properties.
Explanation:
obj.hasOwnProperty fails if object prototype is null or hasOwnProperty is overridden; Object.hasOwn static method avoids this.
Correct Answer: a) undefined
Explanation:
The delete operator removes the property from object, making subsequent lookup return undefined.
Correct Answer: a) Prevents new properties from ever being added to an object.
Explanation:
Object.preventExtensions() prevents addition of new properties, but existing properties can still be modified or deleted.
Correct Answer: a) Object.isFrozen()
Explanation:
Object.isFrozen(obj) returns boolean true if object is frozen.
Correct Answer: a) Object.defineProperty()
Explanation:
Object.defineProperty(obj, prop, descriptor) allows granular configuration of property attributes.
Correct Answer: a) false
Explanation:
Properties added via Object.defineProperty default descriptor flags (enumerable, writable, configurable) to false.
Correct Answer: a) TypeError
Explanation:
In strict mode, attempting to modify a non-writable property raises a TypeError.
Correct Answer: a) The loop skips that property.
Explanation:
Non-enumerable properties are hidden from for...in loops and Object.keys().
Correct Answer: a) Object.getOwnPropertyNames()
Explanation:
Object.getOwnPropertyNames() returns array of all string-keyed property names regardless of enumerability.
Correct Answer: a) Object.getOwnPropertySymbols()
Explanation:
Object.getOwnPropertySymbols(obj) retrieves array of Symbol keys defined on target object.
Correct Answer: a) Reflect.ownKeys()
Explanation:
Reflect.ownKeys(target) returns array containing all own property keys (string names + Symbols).
Correct Answer: a) 30
Explanation:
Object destructuring extracts values of properties 'a' and 'b' into variables. 10 + 20 = 30.
Correct Answer: a) let { a: x } = { a: 10 };
Explanation:
The colon syntax `{ propertyName: localVariableName }` renames destructured properties.
Correct Answer: a) 1 3
Explanation:
Elision (empty comma slot) in array destructuring skips index 1, assigning a=1 and c=3.
Correct Answer: a) 1 10
Explanation:
Default value for 'a' is ignored because value 1 exists. 'b' gets fallback default 10.
Correct Answer: a) [x, y] = [y, x];
Explanation:
Array destructuring assignment `[x, y] = [y, x]` swaps variable values cleanly without temporary variables.
Correct Answer: a) [2, 3, 4]
Explanation:
Rest element `...b` collects remaining unallocated array elements into a new array.
Correct Answer: a) Must always be the last element in destructuring pattern.
Explanation:
Rest elements must appear last in destructuring parameter list, otherwise a SyntaxError occurs.
Correct Answer: a) Shorthand for { a: a }
Explanation:
ES6 object property shorthand allows omitting property value if matching variable name is in scope.
Correct Answer: a) Evaluates bracket expression at runtime to determine object key name.
Explanation:
Square brackets around property key permit dynamic expressions as object property names.
Correct Answer: a) Alice
Explanation:
Computed key `[key]` evaluates variable `key` ("name"), establishing property `obj.name = "Alice"`.
Correct Answer: a) Object.prototype
Explanation:
Plain objects created via literals inherit directly from Object.prototype.
Correct Answer: a) Object.getPrototypeOf()
Explanation:
Object.getPrototypeOf(obj) is standard method for reading target object prototype.
Correct Answer: a) Object.setPrototypeOf()
Explanation:
Object.setPrototypeOf(obj, prototype) changes prototype of target object.
Correct Answer: a) null
Explanation:
Object.prototype's internal prototype is null, marking end of prototype chain.
Correct Answer: a) null
Explanation:
Object.prototype lies at end of standard prototype chain, so its prototype is null.
Correct Answer: a) false
Explanation:
toString is inherited from Object.prototype, not an own property of instance `{}`.
Correct Answer: a) 'in' operator checks prototype chain; hasOwnProperty checks own properties only.
Explanation:
The 'in' operator returns true if property is found on object OR anywhere in prototype chain.
Correct Answer: a) true
Explanation:
The 'in' operator searches prototype chain, finding inherited toString property on Object.prototype.
Correct Answer: a) true
Explanation:
instanceof checks if constructor's prototype appears in target object prototype chain.
Correct Answer: a) true
Explanation:
Array.prototype inherits from Object.prototype, making array instances instances of Object as well.
Correct Answer: a) Binds object property to function evaluated when property is looked up.
Explanation:
Getters bind a property to a function called automatically upon property access.
Correct Answer: a) Binds object property to function executed whenever attempt is made to assign value.
Explanation:
Setters execute custom code when modifying property value.
Correct Answer: a) TypeError: Cannot set property of #<Object> which has only a getter
Explanation:
Attempting to write to a getter-only property in strict mode throws a TypeError.
Correct Answer: a) [1, 99, 3]
Explanation:
ES2023 with(index, value) returns new copy of array with updated value at specified index without mutating original array.
Correct Answer: a) 30
Explanation:
c falls back to default value 30 because index 2 is undefined in array [10, 20].
Correct Answer: a) null
Explanation:
Destructuring default values trigger ONLY on `undefined`. Since value is `null`, variable 'a' receives `null`.
Correct Answer: a) 1
Explanation:
When property value is `undefined`, destructuring activates specified default fallback value 1.
Related Posts
No Image
C++ Inheritance and Polymorphism - MCQs
1. What is the output of `console.log(typeof [1, 2, 3])`? a) array b) object c) list d) undefined Show Answer…
October 19, 2026By MCQs Generator

Java Control Flow / If Else MCQs
Control flow statements in Java determine the exact order in which code instructions and expressions execute during runtime. By default,…
October 19, 2026By MCQs Generator

Java Multithreading & Concurrency MCQs
Java multithreading and concurrency are core pillars for building high-performance, responsive applications that execute multiple tasks simultaneously. Utilizing the java.util.concurrent…
October 19, 2026By MCQs Generator
Related Categories

AI & Data Science MCQ
5 topics
By MCQs Generator

Arts & Humanities MCQ
4 topics
By MCQs Generator

Civil Engineering MCQ
4 topics
By MCQs Generator

Commerce & Business MCQ
4 topics
By MCQs Generator

Competitive Exams MCQ
5 topics
By MCQs Generator

Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator

General Knowledge MCQ
2 topics
By MCQs Generator

General Science MCQ
4 topics
By MCQs Generator

Law & Judiciary MCQ
3 topics
By MCQs Generator

Mechanical Engineering MCQ
4 topics
By MCQs Generator

Medical & Health Sciences MCQ
4 topics
By MCQs Generator

Modern Tech Fields MCQ
3 topics
By MCQs Generator