Help us understand the problem. What is going on with this article?

厳密等価演算子 javaプログラマのjavascript入門

More than 5 years have passed since last update.

==を「等価演算子」
===を「厳密等価演算子」という。
「厳密等価演算子」は型が同じかどうかチェックするが、「等価演算子」はチェックしない。
「等価演算子」を使うと型が異なる場合下記のように変換して比較する。
・数値と文字列を比較するとき、文字列は数値に変換される。
・boolean型ならtrue⇒1、false⇒0に変換される。

var a=1;
var b="1";
var c=true;

// 型が違うが値が同じため真となる
if (a == b) {
document.write('a==b'+'<br/>');
}
// 型が違うため偽となる
if (a === b) {
document.write('a===b'+'<br/>');
}

// 型が違うが値が同じため真となる
if (a == c) {
document.write('a==c'+'<br/>');
}
// 型が違うため偽となる
if (a === c) {
document.write('a===c'+'<br/>');
}

実行結果
a==b
a==c

lasaya
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした