JS_Boolean Logic

  • Comparisons
    • >
    • <
    • >=
    • <=
    • ==
    • !=
    • ===
    • !== 
  • == double equals
    • check 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.
      • 0 == ' ';                  //true
      • 0 == false;            //true
      • null == undefined; //true
  • === triple equals.   checks for equality of value and type
    • 2 === '2';        //false
    • false === 0;   //false
    • 10 !== '10' ;   //ture
    • 10 != '10';     //false
  • console.log().  prints arguments to the console
  • Running code from a file
    • write code in a .js file and inculde the script in a .html file(abover the closing body tag)
    • "hi".toUpperCase(); //won't show up in the console
      
      console.log("hi".toUpperCase());   //will show up in the console.
  • conditions
    • if
    • else if
    • else
    • nesting(多种条件语句嵌套)
  • TRUTHY AND FALSY VALUES
    • all js values have an inherent truthyness or falseness about them
    • false values:
      • false
      • 0
      • ''''(empty string)
      • null
      • undefined
      • NaN
    • everything else is truthy!
  • Logical Operations
    • &&.   AND
    • ||.    OR
    • !    NOT
      • ! null            //true
      • ! (0 === 0) //false
      • ! (3 <= 4).  //false
  • How to check a string includes space or not?
if(string.indexOf(" ") === -1){

         console.log("no space");

}
  • 控制台基本操作
  • alert("hello, welcome to my world!!!")   //在网页面出现弹框
    
    prompt("please introduce yourself~")   //在网页出现输入框,用户可以输入
    "Peiyu Li"
    
    let userInput = prompt("name")
    
    userInput
    "Peiyu"
    
    parseInt("78")     //字符转换成数字
    78
    
    parseInt("78dhkshdk")。 //字符转换成数字,自动滤去非数字部分
    78
    
    console.log("Good morning!!!")。  //输出,相当于print
    Good morning!!!
原文地址:https://www.cnblogs.com/LilyLiya/p/14249686.html