JavaScript & TypeScript / Quiz
Functions Four Ways
Declarations, expressions, arrow functions and IIFEs: hoisting, return values, default parameters and closures.
- Difficulty
- Easy
- Format
- Quiz
- Points
- 100
- Estimate
- 7 min
// MISSION BRIEF
Your Mission
A function can be declared, stored in a variable, written as an arrow, or run on the spot. The four forms look alike and differ in when they exist and what they return.
For each snippet, predict exactly what Node prints. If the code throws, pick the error. Run nothing: read it the way the engine does, top to bottom.
Speed bonus active.
// FIRST CONTACT
Battle teaser
What does this print? If it throws, pick the error. function logStep(step) { console.log("step: " + step); } const result = logStep("login"); console.log(result);
- Astep: login, then null
- Bstep: login, then undefined
- Cundefined, then step: login
- Dstep: login, then login
Answers, scoring, hints, and the full battle stay sealed.
// SKILL TAGS
javascriptfundamentalsfunctionsclosureshoisting