I have been told that in JavaScript,if you assign a value to a variable that has not been declared it will automatically become a global variable, even if it present inside a function.
I have the code:
function helloWorld2(){
greeting2 = "hello world 2";
}
document.write(greeting2);
But netbeans output the following error message:
Uncaught ReferenceError: greeting2 is not defined (15:58:36:083 | error, javascript)
Why is this happening?