What value is returned by arrayFromValue() ?

Submitted 3 years, 6 months ago
Ticket #235
Views 456
Language/Framework Javascript
Priority Low
Status Closed

function arrayFromValue(item) {
  return
    [item];
}

arrayFromValue(10); // => ???
Submitted on Oct 17, 20
add a comment

1 Answer

Verified

During programming it's common to make mistakes here and there,

but if we make mistake like this, like missing a whole line between the return  keyword and [item] expression.

The newline makes the JavaScript automatically insert a semicolon between  return and [item]  expression.

so the written code will be added with the semicolon inserted after return like the code below,

function arrayFromValue(item)

{

       return;

       [item];

}

arrayFromValue(10); // It's undefined

return inside the function makes it return undefined.

So arrayFromValue(10)  evaluates to undefined.

Submitted 3 years, 6 months ago


Latest Blogs