Javascript 4

section 16 javascript decision making

> ,<,>=,<=,==,!=,===,!==

===//strict equality

!==//strict non-equality

10>1; //true
'a'<'b'//true
1=='1'// true
1==='1'//false
null == undefined //true

double equals==:

checks for equality of value, but not equality of type

It coerces both values to the same type and then compares them.

this can lead to some unexpected results

console, alert, prompt

console.log(): prints arguments to the console.

alert("hi")

prompt("please enter a number")

parseInt("101")// 101

if

let rating=3;
if(rating === 3){
  console.log("you are good");
}
else if(rating ===2){
console.log("ok");
}
else{
console.log("ok");
}
const password = prompt("please enter a new password");
//6+ characters password
if (password.length >=6){
//no space in password
    if (password.indexof(' ') === -1){
        console.log("VALID")}
    else{
        console.log("SPACE")
    }
}else{
    console.log("password too short")
}

truthy and falsy values

falsy values:

false

0

""(empty string)

null

undefined

NaN

-everything else is truthy!

        logical

&& || !

true && true // true
false && false //false

true ||false // true

switch statement

const day =2;
switch(day){
    case 1:
        console.log("monday");
        break;
    case 2:
        console.log("tuesday);
    default:
        console.log("invalid")
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值