Skip to main content

ReferenceError at console.log

If variable

console.log(message); // ReferenceError: message is not definedconst message = 'message'

if you reference variable to console.log, then console.log reference variable ⇒ then you reference variable before variable declaration, so it return ReferenceError

If primitive

console.log(3); // primitive value
console.log("string"); // primitive value

you might think this is not reference, so it would be assignment,

this is NOT. because variable doesn’t assign value, it’s just pass the value to console.log