//if - elseconst age =19;const isOldEnough = age >=18;if(age >=18){//ctrl +i 调用出emjoy表情
console.log('Sarah can start driving licnese 🚗')}else{const yearsLeft =18- age;
console.log("Sarah is too young.Wait anoher ${yearsLeft} years :)")}const birthYear =1991;if(birthYear <=2000){
century =20;}else{
century =21;}
console.log(century)
2、类型转换
//类型转换const inputYear ="1991";//转换成数字
console.log(Number(inputYear), inputYear);//1991 '1991'
console.log(Number(inputYear)+18);//2009//转换成字符串
console.log(String(23),23);//23 23//强制类型转换
console.log("I am "+23+"years old");//I am 23years old//加号不行
console.log("23"+"10"+1);//23101
console.log("23"-"10"-3);//10
console.log("23"/"2");//11.5let n ="1"+1;
n = n -1;
console.log(n);//10
3、真值假值
//真值 假值//5个假值 0, ' ', undefined , null , NaN//真值 任何非零数字或者任何非零字符
console.log(Boolean(0));//假
console.log(Boolean(undefined));//假
console.log(Boolean('Jonas'));//真
console.log(Boolean({}));//真
console.log(Boolean(''));//假//类型强制 布尔值 检查变量是否被定义//1.使用逻辑运算符//2.使用if-elseconst money =100;if(money){
console.log("Don't spend it at all")}else{
console.log("You should get a job");}let height;if(height){
console.log('Height is defined');}else{
console.log('Height is UNDEFINED');}
4、双等号与三等号
/// == 判断值// === 判断值 也判断类型 是否完全相同const age =18;if(age ===18) console.log('You just become an adult ');
console.log('18'==18);//true
console.log('18'===18);//falseconst favourite =prompt("What is your favourite number?");
console.log(favourite);
console.log(typeof favourite)if(favourite ===23){
console.log('Cool===!')}elseif(favourite ===7){
console.log(777777777);}else{
console.log('not 23 or 7');}if(favourite !==23) console.log('why not 23');