• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
LilyLiya
博客园    首页    新随笔    联系   管理    订阅  订阅
JS_Boolean Logic
双等号VS三等号;如何判断一个字符串里面是否包含空格; 条件语句;控制台基本操作;
  • 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!!!

     

 

posted on 2021-01-08 03:08  LilyLiya  阅读(67)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3