What Type a function returns?

In the book Eloquent Javascript is the following sentence:

“We need that conversion because the result of prompt is a string value, and we want a number.”

How do I know what Type does a function returns? Is this something you have to memorize, or there is a logic or an easy way to it?

Cheers
Barnabas

1 Like

Hey @barnabas, hope you are great.

You can use the JavaScript function “typeof” which will return the variable type:

var num = 1
var text = "text"

console.log("Variable Type is: "+ typeof(num))
console.log("Variable Type is: "+ typeof(text))

You can read more about it here: https://www.javatpoint.com/javascript-typeof-operator

Carlos Z

2 Likes