I'm learning about hoisting in JavaScript. When I try this code
console.log('name', name)
console.log('age', age)
console.log('occupation', occupation)
var name = 'tom'
var age = '23'
var occupation = 'builder'
in my developer tools in chrome i get
name tom
age undefined
occupation undefined
how come name is not undefined but other variables are?
Edit:
My html file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src = "index.js"></script>
</body>
</html>
My index.js file
console.log('name', name)
console.log('age', age)
console.log('occupation', occupation)
var name = 'tom'
var age = '23'
var occupation = 'builder'
I restarted my computer, created new files and nothing has changed. In firefox I get
name <empty string>
age undefined
occupation undefined