Skip to content
Advertisement

Returning a “typeof” value in a function?

I’m a total beginner, so it would be very helpful if someone posted the full solution in the comments.

I’m trying to solve the following challenge on edabit:

Create a function that takes an array and returns the types of values (data types) in a new array.

JavaScript

So far I have this:

JavaScript

But when I change “return” to a console.log, it gives me a result closer to what I am looking for. Why is that?

JavaScript

Advertisement

Answer

Why is that?

Because return inside a function will return the value and so stop the function, regardless of the for loop.


So use map() to apply it for each item in the array, and then return that array created by map:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement