JavaScript Quiz

Questions: 16 · 10 minutes
1. What does typeof null evaluate to in JavaScript?
""object""
""undefined""
""null""
""boolean""
2. What happens when this code runs: if (true) { let message = ""hello""; } console.log(message);?
It prints ""hello"" because an if block does not create a scope.
A ReferenceError occurs because message is block-scoped.
It prints undefined because message exists but has no value outside the block.
A SyntaxError occurs because let cannot be used inside an if statement.
3. Given const user = {}; what is the result of user.profile?.name?
A TypeError because profile does not exist
null because optional chaining supplies a null value
An empty string because name has not been assigned
undefined because optional chaining stops at the missing property
4. What does [2, 4, 5].every(n => n % 2 === 0) return?
[2, 4]
true, because at least one element is even
5, because that is the first element that fails the test
false, because not every element is even
5. What string is produced by JSON.stringify({ a: 1, b: undefined })?
{""a"":1}
{""a"":1,""b"":undefined}
{""a"":1,""b"":null}
The call returns undefined because one property is undefined.
6. What is produced by [...new Set([1, 1, 2, 2])]?
A four-item array containing 1, 1, 2, and 2
A two-item array containing 2 and 2
A Set object containing the numeric values 1 and 2
A two-item array containing the numeric values 1 and 2
7. If an async function contains return 5;, what does calling that function return?
A Promise fulfilled with the number 5
undefined until the function is awaited
A callback that supplies the number 5
The number 5 immediately, just like a regular function
8. What is the output order of this code: console.log(""A""); setTimeout(() => console.log(""B""), 0); Promise.resolve().then(() => console.log(""C"")); console.log(""D"");?
A, D, C, B
A, D, B, C
A, B, C, D
A, C, D, B
9. What happens after this code runs: const items = [1, 2]; items.push(3);?
It throws an error because a const array cannot be modified.
The array becomes [1, 2, 3] because const prevents rebinding, not mutation of the array.
A new array [1, 2, 3] is created, while items remains [1, 2].
The value 3 is ignored because push only works with arrays declared using let.
10. Consider: const obj = { value: 7, getValue() { const read = () => this.value; return read(); } }; What does obj.getValue() return?
The read function itself rather than its result
undefined, because arrow functions always set this to undefined
7, because the arrow function uses this from getValue
A TypeError because this cannot be used inside a nested function
11. What does Array.prototype.map() normally return?
The original array after replacing each of its elements
One accumulated value calculated from all elements
A new array containing only the elements that pass a test
A new array containing the result of applying a function to each element
12. What value is assigned to limit by const limit = 0 ?? 10;?
10, because 0 is falsy
null, because neither operand is null
0, because nullish coalescing falls back only for null or undefined
undefined, because ?? cannot be used with numeric values
13. After const [first, , third] = [10, 20, 30];, what values do first and third hold?
first is 10 and third is 20
first is 10 and third is 30
first is 20 and third is 30
Both are undefined because an array position was skipped.
14. Consider: function makeCounter() { let n = 0; return () => ++n; } const count = makeCounter(); console.log(count(), count()); What is printed?
0 0
1 2
1 1
0 1
15. What is the main difference between JavaScript's strict equality operator (===) and loose equality operator (==)?
Strict equality compares object contents, while loose equality compares object references.
Strict equality works only with numbers, while loose equality works with all data types.
Strict equality compares values without type coercion, while loose equality may convert types first.
Strict equality is used for assignment, while loose equality is used for comparison.
16. Given const letters = [""a"", ""b"", ""c""]; const removed = letters.splice(1, 1, ""x"", ""y"");, what are letters and removed afterward?
letters is [""a"", ""b"", ""c""] and removed is [""x"", ""y""]
letters is [""a"", ""x"", ""y""] and removed is [""b"", ""c""]
letters is [""a"", ""x"", ""y"", ""c""] and removed is [""b""]
letters is [""a"", ""c"", ""x"", ""y""] and removed is ""b""
Popular tests
Narcissistic Personality Inventory (NPI)
This self-report measure is used to assess narcissism as a personality trai…
Start Test
Yale-Brown Obsessive Compulsive Scale (Y-BOCS)
This measure is used to rapidly quantify the current severity of obsessive…
Start Test
CRAFFT Screening Test (CRAFFT 2.1)
This brief screening measure is designed to identify potential alcohol and…
Start Test
Patient Health Questionnaire-9 (PHQ-9)
This measure is commonly used to quickly screen for the presence and severi…
Start Test
Maslach Burnout Inventory (MBI)
This self-report measure is used to assess occupational burnout symptoms in…
Start Test
Adolescent Anxiety Questionnaire
This measure is designed to support a brief appraisal of anxiety symptoms a…
Start Test
Emotional Creativity Inventory (ECI)
This self-report measure assesses individual differences in the originality…
Start Test
Horne–Ostberg Morningness–Eveningness Questionnaire (MEQ)
Circadian preferences influence typical patterns of alertness and sleep tim…
Start Test
Ambivalent Sexism Inventory (ASI)
This measure is designed to assess attitudes toward women, including both o…
Start Test
Internalized Misogyny Scale (IMS)
This measure is designed to assess internalized negative beliefs and stereo…
Start Test
Perceived Stress Scale (PSS-10)
This self-report measure assesses the degree to which individuals appraise…
Start Test
Impulsive Behavior Scale (SUPPS-P)
Impulsivity is a multidimensional construct that is often assessed with bri…
Start Test
Clinical Institute Withdrawal Assessment for Alcohol, Revised (CIWA-Ar)
This rating scale is used to rapidly assess the severity of alcohol withdra…
Start Test
Positive and Negative Affect Schedule (PANAS)
This measure provides a brief self-report assessment of current or typical…
Start Test
Light Triad Scale (LTS)
This self-report measure assesses prosocial personality tendencies and orie…
Start Test
Suicidal Ideation Scale
In clinical settings, the Suicidal Ideation Scale is used to structure an i…
Start Test
Body Dysmorphic Disorder Scale (BDD-D)
This brief self-report measure is designed to screen for and quantify distr…
Start Test
Beck Anxiety Inventory (BAI)
This measure is a brief self-report inventory used to screen for anxiety sy…
Start Test
Differential Test of Perfectionism
This instrument is used to screen for perfectionism-related attitudes and t…
Start Test
Locus of Control Scale
This measure assesses generalized expectancies regarding the degree to whic…
Start Test
New Apathy Scale
This brief self-report measure is used to screen for apathy-related symptom…
Start Test
Perth Alexithymia Questionnaire (PAQ)
This measure assesses individual differences in alexithymia, including diff…
Start Test
Social Intelligence Scale
This brief self-report measure is designed to support rapid screening of in…
Start Test
Fear Test
This measure is designed to evaluate individual differences in fear-related…
Start Test
Neuroticism Level Scale
The measure is intended for brief screening of an individual’s propensity t…
Start Test
Aggressiveness Indicators Screening Questionnaire
This screening tool is designed to quickly identify behavioral indicators a…
Start Test