記事の作成日 : 2020/02/15
if文を、使ってみるよ。50 です。( abc = 50; )
注目する場所は、abc == 50 です
let abc = 0;
// abc = ?? ;
if ( abc == 50 ){
alert("ナイス!");
}
値が一致したとき成立する式です。
// 成立する (true)
30 == 30 ;
"hello" == "hello" ;
30 == "30" ; //逆も可
// 成立しない (false)
30 == 2 ;
"hello" == "hey" ;
25 == "65" ;
// 成立する (true)
30 === 30 ;
"hello" === "hello" ;
// 成立しない (false)
30 === 2 ;
"hello" === "hey" ;
25 === "25" ;
// 宣言
let apple = 20 ;
// 不等式 javascript の方が、日本語よりわかりやすい気がします。
if ( apple > 10 ){
alert("apple は 10 より大きい( 11~ )です");
}
if ( apple < 10 ){
alert("apple は 10 より小さい( ~9 )です");
}
if ( apple >= 10 ){
alert("apple は 10 以上( 10~ )です");
}
if ( apple <= 10 ){
alert("apple は 10 以下( ~10 )");
}
if ( apple <> 10){
alert("apple は 10 以外です");
}