[SOLVED] Why does the typeof return undefined not string

Issue

Why does the typeof return undefined not string

myFunction();
function myFunction(){
var address = '12345, Abuja,Nigeria'
}
console.log('the address is' + typeof  address)

Solution

The variable address is not defined within the scope of where you are trying to use it. The variable only exists inside the "myFunction" function. If you move the console.log into the function block it should work as you expect.

Answered By – Gustavo Cesário

Answer Checked By – Dawn Plyler (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.