my new string is unassigned to a variable or something.
who writes this stuff what happens to simple English.
anywho. its wrong and it works in Repl.it.
The error message is pretty clear if you think about it, “not defined”. Meaning it can’t find the identifier.
It’s like if I spoke a sentence to you and used a non-existing word, like “Hey royalgreen50 how are heifhiefhijf”. Your brain would get to “heifhiefhijf” and not find the definition of the word in its memory and “throw an error”. The engine will throw a Reference Error Uncaught ReferenceError: heifhiefhijf is not defined because it can’t find the definition for heifhiefhijf anywhere.
The reason why it works in some environments is that JavaScript will try to be “helpful” by automatically making the identifier global and put it on the global object.
function JSPleaseHelp() {
notTheRightWay = 'silliness';
return notTheRightWay;
}
JSPleaseHelp()
"silliness"
/* notTheRightWay is now on the global object, in this case, the window object */
window.notTheRightWay
"silliness"
If you set the 'use strict' directive it will error out instead
function JSPleaseDoNotHelp() {
'use strict'
notTheRightWay = 'silliness';
return notTheRightWay;
}
JSPleaseHelp()
Uncaught ReferenceError: notTheRightWay is not defined
BTW, the guide article has been updated on master but the site has not yet been updated. You have to be a bit careful about copying some of the guide article code, they are not all correct anymore. At least not until the update.