LoginSignup
0
0

More than 3 years have passed since last update.

JavaScriptをMacのターミナルで使用する時の注意点

Posted at

Macのターミナルで初めてJavaScriptを実行した際に、基本的なところでエラーが出たのでその対処法を書いていきます。

console.log()でエラー

まずJavaScript標準で用意されているオブジェクトのnowDate()を用いて、今日の日付と今の時刻を表示しようとしました。

nowDate.js
const today = nowDate();

console.log(today);

こちらのjsファイルをターミナルで実行すると、

Exception: TypeError: undefined is not an object (evaluating 'console.log')

このようなエラーが出てきました。

print()に変更

nowDate.js
const today = nowDate();

print(today);

このように変更して実行すると、

Fri Aug 09 2019 11:24:41 GMT+0900 (JST)

先ほどのようなエラーが起きず無事に現在の日付・時刻を表示できました。

まとめ

エラーが出ても、焦らず冷静に開発環境やコードをチェックしていきたいですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0