Where is 'undefined' coming from in this little script?

It may just be too early in the morning for me ... I've got this super simple little script, and it outputs the correct text depending on what scene is loaded, but immediately after it gives me an 'undefined' with no more information. No line number, no "what" is undefined.

Can anyone see what's causing it?

whereami.png


Code:
whereami = function() {
    if (SceneManager.isScene(Scene_Map)) {
        console.log('you are on the map');
    } else {
        console.log('you are not on the map');
    }
};


SceneManager.isScene = function(sceneClass) {
    return this._scene && this._scene.constructor === sceneClass;
};
Every time you get a console.log from the console it gives you that. (Try "console.log('hello');". ) True in my regular Chrome browser console as well. Not sure why it does that when calling the command from the console but not while running code directly, maybe someone else knows.
I guess it's a bug in nw.js. But for some reason everytime you use an if condition or for loop in combination with console.log (maybe even console.log alone), you're going to have one line of undefined. These are not the only cases of undefined, I often get undefined lines by triggering functions with no return values through console as well.

Also, as you can see, there is no reference as to where the undefined comes from. Your console.logs come from line 3 and line 5 of test.js, but undefined has no reference in terms of script locations. So don't worry, the code is fine.

Edit: Ninja'd for once 😀 @Llareian
That is so weird! I don't recall having ever seen that before!

Thanks - as long as it's not an issue with my code, I'm happy 🙂
I think it's outputting the return of the last statement. Try writting this in the console:
Code:
whereami();
2;

Since whereami() has no return, it's undefined.
It's not a bug, it's the result of the code you wrote. As Fhntop said, since the function has no return value, the result is undefined.
Since whereami() has no return, it's undefined.

Thank you! That makes perfect sense.
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/where-is-undefined-coming-from-in-this-little-script.90424/