0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

数値と計算

Last updated at Posted at 2025-03-15

プログラミングでは、数値(数字)を扱うこともでき、足し算、引き算、掛け算、割り算の計算をすることができます。

※注意点
数値は文字列と違い、クォーテーションで囲みません。数値と記号はすべて半角で記述することに注意しましょう。

【足し算「+」、引き算「-」】

qiita.js
console.log(3);
console.log(5+2);
console.log(3-2);
出力結果/コンソール
3
7
1

【⽂字列と数値】

下の図のように、console.log(5 + 2);は足し算の結果である数値の7が出力されます。
一方、5 + 2にダブルクォーテーション("")をつけると、プログラム上で文字列として5 + 2と出力されます。

文字列と数値は明確に違うものであることを意識しましょう。

例題

以下の例題に取り組んでみましょう。

//5と3を足した値を出力してください

//20から8を引いた値を出力してください

//"4+5"を文字列として出力してください
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?