0
0

More than 5 years have passed since last update.

JavaScript で の数値 の 扱い 〜console.log("5 + 2");とconsole.log(5 + 2);の違い〜

Posted at

目的

  • JavaScriptの数値の取り扱いについてまとめる。

押さえるポイント

  • コンソールに文字列を出力するときはconsole.log("表示したい文字列");とする。
  • コンソールに足し算の結果を出力するときはconsole.log(足し算など);とする。
  • 表示したい文字列をカッコ内にシングルクオートかダブルクオートで囲んで書く。
  • 表示したい数値はカッコ内をシングルクオートやダブルクオートで囲まない
  • 足し算、引き算の符号は数値と半角スペースを空ける。
  • 最後にセミコロンを忘れずに。

書き方の例

  • 「△」「○」は足し算したい数値が入る
  • 下記にJavaScriptファイルの内容を記載する。
console.log( + );

より具体的な例

  • コンソールに5+2の結果と10-2の結果を表示するコードを書く。
  • 下記にJavaScriptファイルの内容を記載する。
//これはコンソールに「5 + 2」と出力するコードです。
console.log("5 + 2");

//これはコンソールに5+2の結果を出力するコードです。
console.log(5 + 2);

//これはコンソールに10-2の結果を出力するコードです。
console.log(10 - 2);
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