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") }