6
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 3 years have passed since last update.

【JavaScript問題】「700 / 500 | 0 」の出力結果は?

Last updated at Posted at 2022-04-30

なんだこの書き方は?っというのがあったので調べて理解したので、投稿しておきます

答え

700 / 500 | 0
= > 1

理由

まず、700 / 500 = 1.4 です。
"|"はビットの論理和であり、整数の演算子です

※補足

整数・・・実数の分類の1つで、正の整数(自然数)、ゼロ、負の整数のみ
実数・・・有理数と無理数

これを使った時点で、左側が実数から整数に変換され、小数点が消えて、"1"になります。
右の値が"0"なのでそのまま左の整数の値"1"が得られます。

補足

5 | 3 = 7 です

理由は以下です

const a = 5;        // 00000000000000000000000000000101
const b = 3;        // 00000000000000000000000000000011

console.log(a | b); // 00000000000000000000000000000111
// expected output: 7

最後に一言

何か間違っている点があれば、教えて頂けたら幸いです。
よろしくお願い致します。
また「いいね!」してもらえるとすごい嬉しいです!!

6
1
2

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
6
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?