JavaScript 不同的结果?

JavaScript Different Results?

我对 JavaScript 有点陌生(从 CodeCademy 学习),我想知道为什么会这样:

function Person(job, married) {
    this.job = job;
    this.married = married;
    // add a "speak" method to Person!
    this.speak = function()
    {
        console.log("Hello!");
    };
}

var user = new Person("Codecademy Student",false);
user.speak();

我在 CodeCademy 解释器中 运行 这段代码,但它 returns 一个错误,说明如下:

Oops, try again. It looks like 'Hello!' wasn't logged to the console. Make sure that you properly defined the method and that you didn't change any of the provided code.

但是,我的朋友推荐我使用在线 JavaScript 控制台

https://repl.it/ (which actually has support for a lot of other languages too!), and it shows me that it is printing "Hello!"

我不太清楚网站为什么这样做,或者为什么它与在线控制台不同。我很确定我已经仔细检查以确保代码完全相同...

学习的最佳位置 javascript 是浏览器的开发者工具栏。 如果您使用的是 Firefox,请下载 FireBug 作为插件。将您的代码放入控制台并点击 运行 按钮。 或者您可以使用任何其他浏览器来执行相同的操作。只需在任何浏览器中按 F12 即可打开开发人员控制台。