Quiz: Do You Know Modern JavaScript?
Prove your esteemed JavaScript skillz!
Do you know your ES2015 from ES2022?
- Prove your JavaScript skillz! 🚀
- No login or signup required. ✨
- Multiple choice. 🤖 … How difficult can it be, eh?
What is the output of the following code?
The optional chaining operator (?.
) stops the evaluation if the left-hand side is null
or undefined
. Since obj.foo
is null
, obj.foo?.bar
evaluates to undefined
.
What does the import()
function return?
The import()
function returns a Promise
that resolves to the module object. In this case, typeof modulePromise
will return 'object'
, as it is an instance of Promise
.
What will be the result of the following code?
Promise.allSettled
returns an array of objects describing the outcome of each promise. The first promise is fulfilled
with the value 'success'
, so the log statement will print Fulfilled: success
.
What does str.matchAll()
return?
String.matchAll
returns an iterator of matches, not an array. This iterator can be used to get all the matching groups from a string.
What does import.meta.url
represent?
import.meta
is an object that contains metadata about the current module. The import.meta.url
property represents the URL of the current module, which can be used to get information about where the script is running.
What is the value of a
after the logical assignment?
The logical OR assignment (||=
) assigns the right-hand value if the left-hand value is falsy (null
, undefined
, 0
, false
, etc.). Since a
is null
, it is assigned the value 10
.
What is the value of b
after the nullish assignment?
The nullish coalescing assignment (??=
) assigns the right-hand value if the left-hand value is null
or undefined
. Since b
is null
, it is assigned the value 10
.