2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

四則演算とは

Last updated at Posted at 2024-02-09

四則演算とは 

算術計算で最も基本的な4つの計算法である足し算、引き算、掛け算、割り算のこと。

  定義   コード 
足し算 例 (num1 + num2 )
引き算   例 ( num1 - num2 )
掛け算   * 例 ( num1 * num2 )
割り算 / 例 ( num1 / num2 )
余り 例 ( num1 % num2 )
  console.log( 5  2 ); ・・・出力結果 7
  //5と2を足しているので出力すると7が表示されます
  console.log( 6 / 3 ); ・・・ 出力結果 2
 //6を2で割っているので出力すると2が表示されます

上記では数字を使いましたが、文字も足したりすることができます。

そのためにはまず (")ダブルクォート、(')シングルクォート、
(`)バッククォートとで囲む必要があります。

ダブルクォート      シングルクォート     バッククォート
   "    '     `
  文字列   文字列   変数の埋め込みや複数行の文字列
 ("今日は") ('いい天気')  (`)で囲んだ文字列内に ${< 変数名>} を埋め込むことができる

上記の文字列を使った例です

   let address = '東京都' '千代田区';
   console.log(address); //東京都と千代田区を足している      
   出力結果 ・・・  東京都千代田区
  let name = "佐藤さん";
  console,log(`こんにちは、${name}さん!`); //nameを入れることで佐藤さんを出力することができる
  出力結果 ・・・ こんにちは佐藤さん

最後に

 文字列と数値の違い
"3"+"5" は "35" という文字列になりますが、 3 + 5 は 8になります。
なので文字列と数値を入力する時は、別物だということを理解しておきましょう。

また自分で文字や数値を変え、試してみるとより分かりやすいと思うのでぜひ試してみてください。

2
1
1

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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?