Certified Associate JavaScript Programmer study materials
Certified Associate JavaScript Programmer study resources

Certified Associate JavaScript Programmer practice questions

One question at a time. Build your Certified Associate JavaScript Programmer understanding.

First 50 of 200 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.

Continue in the practice tool above to load more questions, 50 at a time.

Question 1JavaScript language fundamentals and vendor-neutral certification scope

Which declaration creates a block-scoped binding that cannot be reassigned after initialization?

  1. const total = 10; Correct answer.
  2. var total = 10;
  3. total = 10;
  4. let total = 10;

Explanation

The const keyword creates a binding scoped to the enclosing block and forbids reassignment after the initializer runs. It does not make the referenced object immutable, only the binding itself.

Question 2JavaScript language fundamentals and vendor-neutral certification scope

What does typeof null evaluate to in JavaScript?

  1. "object" Correct answer.
  2. "undefined"
  3. "boolean"
  4. "null"

Explanation

typeof null returns the string "object", a long-standing inconsistency retained for backward compatibility. A null check therefore requires an explicit value === null comparison rather than typeof.

Question 3JavaScript language fundamentals and vendor-neutral certification scope

A function is invoked as a plain call inside non-strict code. What does `this` reference inside that function?

  1. undefined
  2. The global object Correct answer.
  3. The function object itself
  4. A new empty object

Explanation

In sloppy mode a plain function call binds this to the global object, because the call has no receiver. In strict mode the same call would bind this to undefined instead.

Question 4JavaScript language fundamentals and vendor-neutral certification scope

Which value is produced by the expression `0.1 + 0.2 === 0.3`?

  1. A TypeError is thrown
  2. NaN
  3. true
  4. false Correct answer.

Explanation

Binary floating-point cannot represent 0.1 and 0.2 exactly, so their sum is slightly greater than 0.3 and the strict comparison fails. Comparing with a tolerance such as Number.EPSILON is the usual remedy.

Question 5JavaScript language fundamentals and vendor-neutral certification scope

What is the result of `[1, 2, 3].map(x => x * 2)`?

  1. [2, 4, 6] Correct answer.
  2. [1, 2, 3]
  3. [2, 4, 6, 8]
  4. 6

Explanation

map invokes the callback once per element, collects each return value, and produces a new array of the same length. The original array is left unchanged.

Question 6JavaScript language fundamentals and vendor-neutral certification scope

Which statement about `let` and `var` inside a for loop body is accurate?

  1. Neither creates a fresh binding per iteration
  2. Only var creates a fresh binding per iteration
  3. Only let creates a fresh binding per iteration Correct answer.
  4. Both create a fresh binding on each iteration

Explanation

A let declaration in a for loop head creates a new binding for each iteration, which is why closures capture distinct values. var has a single function-scoped binding shared by all iterations.

Question 7JavaScript language fundamentals and vendor-neutral certification scope

Which expression converts the string "42" to the number 42?

  1. String(42)
  2. Boolean("42")
  3. Number("42") Correct answer.
  4. "42" + 0

Explanation

The Number function performs explicit numeric conversion and returns 42 for this input. The unary plus operator would do the same, but concatenating with the string "0" produces text.

Question 8JavaScript language fundamentals and vendor-neutral certification scope

What does `typeof undefinedVariable` return when the identifier was never declared?

  1. "undefined" Correct answer.
  2. "object"
  3. "null"
  4. A ReferenceError is thrown

Explanation

typeof is the one operator that tolerates an undeclared identifier, returning the string "undefined" instead of throwing. Evaluating the bare identifier without typeof would raise a ReferenceError.

Question 9JavaScript language fundamentals and vendor-neutral certification scope

Which statement correctly describes how `==` and `===` differ?

  1. === performs type coercion while == requires matching types
  2. == performs type coercion before comparison while === requires matching types Correct answer.
  3. == compares types only while === compares values
  4. Both always behave identically for primitives

Explanation

The loose equality operator applies the abstract equality algorithm, coercing operands to a common type, whereas strict equality returns false immediately when the types differ. Using === avoids surprising coercions such as "1" == 1 being true.

Question 10JavaScript language fundamentals and vendor-neutral certification scope

What is logged by `console.log([] + {})`?

  1. "[]"
  2. "[object Object]" Correct answer.
  3. A TypeError is thrown
  4. NaN

Explanation

The + operator converts both operands to primitives; the array becomes the empty string and the plain object becomes "[object Object]". String concatenation then joins them into "[object Object]".

Question 11JavaScript language fundamentals and vendor-neutral certification scope

Inside a method defined with shorthand syntax on an object literal, what does `this` refer to when called as `obj.method()`?

  1. The global object
  2. obj Correct answer.
  3. The prototype of obj
  4. undefined

Explanation

When a function is invoked as a property of an object, the base object becomes the receiver and this is bound to it. This holds for shorthand methods and for traditional function-valued properties alike.

Question 12JavaScript language fundamentals and vendor-neutral certification scope

Which statement about arrow functions is correct?

  1. They create a new prototype object
  2. They bind `this` lexically from the enclosing scope Correct answer.
  3. They receive their own `arguments` object
  4. They can be used with the new operator

Explanation

Arrow functions have no this binding of their own and instead capture the this of the surrounding lexical scope. They also lack arguments, prototype, and new-target support, which makes them unsuitable as constructors.

Question 13JavaScript language fundamentals and vendor-neutral certification scope

What is the value of `x` after `let x = 1; { let x = 2; }`?

  1. 2
  2. 1 Correct answer.
  3. undefined
  4. A SyntaxError is thrown

Explanation

The inner let declares a new binding in the nested block, which shadows the outer one only inside that block. When the block ends the inner binding is gone, leaving the outer x at 1.

Question 14JavaScript language fundamentals and vendor-neutral certification scope

What is the result of `"5" - 2`?

  1. "52"
  2. NaN
  3. 3 Correct answer.
  4. "3"

Explanation

The subtraction operator only performs numeric arithmetic, so it coerces the string "5" to the number 5 and yields 3. The + operator would instead concatenate because one operand is a string.

Question 15JavaScript language fundamentals and vendor-neutral certification scope

In `function f(a, b = a * 2) {}`, which call is valid?

  1. f(b = 4)
  2. f()
  3. f(3) Correct answer.
  4. f(3, 4, 5)

Explanation

Default parameters may reference earlier parameters, so calling f(3) evaluates b as 6. Passing extra arguments is also legal in JavaScript, but that does not make the other listed forms specially valid.

Question 16JavaScript language fundamentals and vendor-neutral certification scope

Which statement about `Array.prototype.forEach` is accurate?

  1. It returns undefined and is used for side effects Correct answer.
  2. It returns a new array of results
  3. It skips holes in sparse arrays by throwing
  4. It stops early when the callback returns false

Explanation

forEach always returns undefined; its purpose is to run a callback for each visited element for side effects. It cannot be short-circuited, unlike a for loop with break or the some and every methods.

Question 17JavaScript language fundamentals and vendor-neutral certification scope

What is logged by `console.log(typeof typeof 1)`?

  1. "object"
  2. "string" Correct answer.
  3. "undefined"
  4. "number"

Explanation

The inner typeof 1 evaluates to the string "number", and typeof applied to that string yields "string". Operator grouping is right to left here, and typeof always returns a string.

Question 18JavaScript language fundamentals and vendor-neutral certification scope

Which code correctly creates a shallow copy of an array `arr` without mutating it?

  1. const copy = arr;
  2. const copy = arr.reverse();
  3. const copy = arr.sort();
  4. const copy = arr.slice(); Correct answer.

Explanation

slice with no arguments returns a new array containing the same elements, leaving the source untouched. Assigning the reference or calling mutating methods like reverse and sort would not produce an independent copy.

Question 19JavaScript language fundamentals and vendor-neutral certification scope

What happens when a variable declared with `let` is read inside its temporal dead zone?

  1. It throws a TypeError
  2. It throws a ReferenceError Correct answer.
  3. It reads the value from an outer scope
  4. It evaluates to undefined

Explanation

A let or const binding exists from the start of its block but is uninitialized until its declaration executes. Accessing it during that window throws a ReferenceError, which is different from var hoisting to undefined.

Question 20JavaScript language fundamentals and vendor-neutral certification scope

Given `const fns = []; for (var i = 0; i < 3; i++) { fns.push(() => i); }`, what does `fns.map(f => f())` return?

  1. [0, 0, 0]
  2. [3, 3, 3] Correct answer.
  3. [0, 1, 2]
  4. [undefined, undefined, undefined]

Explanation

var creates one function-scoped binding shared by all three closures, and the loop increments it to 3 before any closure runs. Every arrow therefore reads the final value 3. Replacing var with let would give per-iteration bindings and produce [0, 1, 2].

Question 21JavaScript language fundamentals and vendor-neutral certification scope

What is the outcome of `Object.freeze(obj)` followed by `obj.prop = 1` in strict-mode code?

  1. A TypeError is thrown Correct answer.
  2. The property is set to 1
  3. The assignment is silently ignored
  4. A ReferenceError is thrown

Explanation

Freezing makes existing properties non-writable, and strict mode converts failed writes into thrown TypeErrors. In sloppy mode the same assignment would fail silently instead of throwing.

Question 22JavaScript language fundamentals and vendor-neutral certification scope

What does `[10, 1, 2].sort()` return?

  1. [1, 10, 2] Correct answer.
  2. [1, 2, 10]
  3. [2, 1, 10]
  4. [10, 1, 2]

Explanation

Without a comparator, sort converts elements to strings and orders them by UTF-16 code units, so "10" precedes "2". A numeric comparator such as (a, b) => a - b is required for numeric ordering.

Question 23JavaScript language fundamentals and vendor-neutral certification scope

Which statement best explains why `NaN === NaN` is false?

  1. The === operator returns false for all number comparisons
  2. NaN is coerced to 0 before comparison
  3. NaN is an object, so identity comparison fails
  4. The IEEE 754 standard defines NaN as unequal to every value including itself Correct answer.

Explanation

NaN represents an invalid numeric result and by IEEE 754 semantics compares unequal to everything, itself included. Number.isNaN or Object.is(NaN, NaN) must be used to detect it reliably.

Question 24JavaScript language fundamentals and vendor-neutral certification scope

A function returns an inner function that reads a variable declared in the outer function. After the outer function returns, what happens to that variable?

  1. It becomes undefined
  2. It remains accessible through the closure Correct answer.
  3. It is copied into the global scope
  4. It is garbage collected immediately

Explanation

A closure keeps a reference to the lexical environment in which the inner function was created, so the outer variable survives as long as the inner function is reachable. This is the mechanism behind module patterns and private state.

Question 25JavaScript language fundamentals and vendor-neutral certification scope

What is the value of `1 + 2 + "3"`?

  1. 6
  2. "6"
  3. "123"
  4. "33" Correct answer.

Explanation

The + operator is left-associative, so 1 + 2 evaluates numerically to 3 first. The next addition involves the string "3", which triggers concatenation and produces "33".

Question 26JavaScript language fundamentals and vendor-neutral certification scope

Which value is produced by the expression `Boolean('0')` in JavaScript?

  1. NaN
  2. false
  3. undefined
  4. true Correct answer.

Explanation

The Boolean conversion of any non-empty string is true, and the string '0' contains one character, so it is truthy. Only the empty string '' converts to false among strings. This differs from the number 0, which does convert to false.

Question 27JavaScript language fundamentals and vendor-neutral certification scope

Which declaration creates a block-scoped binding that can be reassigned later?

  1. const count = 0;
  2. function count() {}
  3. let count = 0; Correct answer.
  4. var count = 0;

Explanation

`let` creates a binding scoped to the enclosing block and permits reassignment. `const` is also block-scoped but forbids reassignment of the binding, and `var` is function-scoped rather than block-scoped.

Question 28JavaScript language fundamentals and vendor-neutral certification scope

A developer writes `const s = 'abc'; console.log(s.length);`. What is printed?

  1. TypeError
  2. NaN
  3. 3 Correct answer.
  4. undefined

Explanation

String primitives expose properties through automatic boxing, so `s.length` reads the number of UTF-16 code units, which is 3 for 'abc'. No error occurs and the value is a number.

Question 29JavaScript language fundamentals and vendor-neutral certification scope

Which operator returns the remainder of a division in JavaScript?

  1. /
  2. //
  3. % Correct answer.
  4. mod

Explanation

The percent sign `%` is the remainder operator, so `7 % 3` evaluates to 1. It works on numbers and preserves the sign of the dividend.

Question 30JavaScript language fundamentals and vendor-neutral certification scope

What is the result of `typeof null`?

  1. "undefined"
  2. "object" Correct answer.
  3. "null"
  4. "boolean"

Explanation

`typeof null` returns the string "object" because of a long-standing historical behavior in the language, even though null is its own primitive type. Checking for null therefore requires `value === null` rather than a typeof test.

Question 31JavaScript language fundamentals and vendor-neutral certification scope

Which statement about `Array.isArray` is accurate?

  1. It returns true for any object with a numeric length property.
  2. It throws when passed a non-object value such as a number.
  3. It returns true only for arrays created in the current global context.
  4. It returns true for arrays created in any realm, such as another iframe. Correct answer.

Explanation

`Array.isArray` performs a brand check that works across realms, so arrays from iframes or other contexts are detected correctly. It returns false for array-like objects and never throws for primitive arguments.

Question 32JavaScript language fundamentals and vendor-neutral certification scope

Which value is returned by `Number.parseInt('12px', 10)`?

  1. 0
  2. "12"
  3. 12 Correct answer.
  4. NaN

Explanation

`parseInt` reads leading characters that form a valid integer and stops at the first invalid one, so '12px' yields 12. It returns a number, not a string, and only returns NaN when no leading digits exist.

Question 33JavaScript language fundamentals and vendor-neutral certification scope

Which construct creates a new array containing the results of calling a function on every element?

  1. Array.prototype.filter
  2. Array.prototype.reduce
  3. Array.prototype.map Correct answer.
  4. Array.prototype.find

Explanation

`map` produces a new array of the same length whose entries are the callback return values. `filter` keeps original elements that pass a test, `reduce` collapses to a single value, and `find` returns one element.

Question 34JavaScript language fundamentals and vendor-neutral certification scope

What does `console.log(0.1 + 0.2 === 0.3)` print?

  1. undefined
  2. true
  3. false Correct answer.
  4. NaN

Explanation

Binary floating point cannot represent 0.1 and 0.2 exactly, so their sum is slightly greater than 0.3 and strict equality fails. The comparison itself returns a boolean, so the output is false.

Question 35JavaScript language fundamentals and vendor-neutral certification scope

Given `const obj = {a: 1}; const copy = {...obj}; copy.a = 2;`, what is `obj.a`?

  1. 1 Correct answer.
  2. undefined
  3. 2
  4. TypeError

Explanation

The spread syntax creates a new object with copied own enumerable properties, so changing `copy.a` does not affect `obj.a`. The original remains 1 because the two objects are distinct.

Question 36JavaScript language fundamentals and vendor-neutral certification scope

What is logged by `console.log([1, 2, 3].includes(2))`?

  1. true Correct answer.
  2. false
  3. undefined
  4. 1

Explanation

`Array.prototype.includes` performs a SameValueZero comparison and returns a boolean indicating whether the value is present. Since 2 is an element, it returns true.

Question 37JavaScript language fundamentals and vendor-neutral certification scope

Which statement about the `default` clause of a `switch` statement is accurate?

  1. It runs in addition to any matching case.
  2. It must be the final clause in the switch block.
  3. It is required whenever the switch has more than one case.
  4. It runs when no case matches, regardless of its position in the switch block. Correct answer.

Explanation

The `default` clause is selected when no case expression matches, and its location within the block does not change that selection. It is optional and does not run alongside a matched case unless fall-through reaches it.

Question 38JavaScript language fundamentals and vendor-neutral certification scope

What does `try { throw new Error('x'); } catch (e) { console.log(e.message); } finally { console.log('done'); }` output, in order?

  1. done then x
  2. x then done Correct answer.
  3. done only
  4. x only

Explanation

The catch block handles the thrown error and logs its message first, then the finally block always executes and logs 'done'. Both lines are printed in that order.

Question 39JavaScript language fundamentals and vendor-neutral certification scope

Which statement about `Object.keys(obj)` is accurate?

  1. It returns an array of the object's own enumerable string-keyed property names. Correct answer.
  2. It returns an array of the property values rather than names.
  3. It returns a Map of keys to values.
  4. It returns an array of all property names, including inherited ones.

Explanation

`Object.keys` collects own enumerable string keys into a new array, excluding inherited properties and non-enumerable ones. Use `Object.getOwnPropertyNames` to include non-enumerable keys or `Object.values` for values.

Question 40JavaScript language fundamentals and vendor-neutral certification scope

What is the value of `'5' * '2'`?

  1. NaN
  2. '10'
  3. '52'
  4. 10 Correct answer.

Explanation

The multiplication operator coerces both string operands to numbers, so '5' and '2' become 5 and 2 and the product is 10. Unlike the plus operator, multiplication has no string concatenation behavior.

Question 41JavaScript language fundamentals and vendor-neutral certification scope

Which statement about `Array.prototype.slice` is accurate?

  1. It returns the index of the first matching element.
  2. It reverses the source array and returns it.
  3. It removes the selected range from the source array in place.
  4. It returns a shallow copy of the selected range without modifying the source array. Correct answer.

Explanation

`slice` copies the chosen range into a new array and leaves the original untouched. Its shallow nature means object elements are shared by reference between the copy and the source.

Question 42JavaScript language fundamentals and vendor-neutral certification scope

What is logged by `console.log(typeof NaN)`?

  1. "undefined"
  2. "object"
  3. "NaN"
  4. "number" Correct answer.

Explanation

NaN is a special numeric value of the Number type, so `typeof` reports "number". This is why `Number.isNaN` is preferred over a typeof check for detecting NaN.

Question 43JavaScript language fundamentals and vendor-neutral certification scope

A function is called as `obj.method()` where `method` was assigned an arrow function defined in the outer scope. What does `this` inside that arrow function reference?

  1. A new empty object
  2. The `this` value of the enclosing lexical scope where the arrow was created Correct answer.
  3. `undefined` in all cases
  4. The object `obj`

Explanation

Arrow functions do not have their own `this`; they capture the `this` of the scope in which they were defined. Calling the arrow as a property of `obj` does not rebind `this` to `obj`.

Question 44JavaScript language fundamentals and vendor-neutral certification scope

What does `console.log(2 ** 3 ** 2)` evaluate to?

  1. 18
  2. 64
  3. SyntaxError
  4. 512 Correct answer.

Explanation

The exponentiation operator is right-associative, so the expression groups as `2 ** (3 ** 2)`, which is `2 ** 9` and equals 512. Left-associative evaluation would give 64 but is not how the operator behaves.

Question 45JavaScript language fundamentals and vendor-neutral certification scope

Which statement correctly describes the behavior of `for...of` on a string?

  1. It iterates the string's enumerable property names.
  2. It cannot be used with strings and throws a TypeError.
  3. It iterates UTF-16 code units, splitting surrogate pairs.
  4. It iterates code points, so astral characters such as emoji are yielded as single units. Correct answer.

Explanation

Strings implement the iterable protocol, and their default iterator yields code points rather than raw code units. This means characters outside the Basic Multilingual Plane are produced intact.

Question 46JavaScript language fundamentals and vendor-neutral certification scope

What is the result of `JSON.stringify({a: undefined, b: 1})`?

  1. {"a":null,"b":1}
  2. {"a":undefined,"b":1}
  3. undefined
  4. {"b":1} Correct answer.

Explanation

Object properties whose values are undefined are omitted entirely during serialization, so only `b` appears in the output. In arrays, by contrast, undefined entries become null.

Question 47JavaScript language fundamentals and vendor-neutral certification scope

Given `const a = [1, 2, 3]; const b = a; b.push(4);`, what is `a.length`?

  1. undefined
  2. 3
  3. TypeError
  4. 4 Correct answer.

Explanation

Arrays are objects, and assigning `a` to `b` copies the reference rather than the array. Both names therefore point to the same array, so pushing through `b` changes the length seen through `a`.

Question 48JavaScript language fundamentals and vendor-neutral certification scope

What is logged by `console.log([1, 2, 3].reduce((acc, v) => acc + v))`?

  1. NaN
  2. undefined
  3. 0
  4. 6 Correct answer.

Explanation

With no initial value supplied, `reduce` uses the first element as the accumulator and begins iterating from the second. The result is 1 + 2 + 3, which is 6.

Question 49JavaScript language fundamentals and vendor-neutral certification scope

Which statement about property lookup on an object created with `Object.create(proto)` is accurate?

  1. `Object.create` copies the prototype's properties onto the new object.
  2. Assigning a property that exists on the prototype overwrites the prototype's property.
  3. The prototype chain is not consulted when reading a missing own property.
  4. Own properties shadow same-named properties found on the prototype chain. Correct answer.

Explanation

Lookup checks own properties first and only then walks the prototype chain, so an own property hides a same-named inherited one. Assignment creates or updates an own property and does not modify the prototype object.

Question 50JavaScript language fundamentals and vendor-neutral certification scope

What does `console.log(Object.is(NaN, NaN))` print?

  1. false
  2. NaN
  3. true Correct answer.
  4. TypeError

Explanation

`Object.is` uses SameValue semantics, under which NaN is considered equal to itself, unlike the strict equality operator. It also treats +0 and -0 as different, which is another difference from `===`.