Falsy VS Truthy Value and == VS ===

  • Falsy values: undefined, null, 0, '', NaN
  • Truthy values: Not falsy values
var height;

    if (height) {
console.log('Variable is defined');
} else {
console.log('Variable has NOT been defined');
}

In this code above, the result is: Variable has NOT been defined, because height is undefined -- falsy value

So, if we insert height = 23 before if, height will become a truthy value. The result will be Variable is defined

	var height;
height = 23;
if (height) {
console.log('Variable is defined');
} else {
console.log('Variable has NOT been defined');
}

But again, if height = 0; , it will return Variable has NOT been defined

    var height;
height = 0;
if (height) {
console.log('Variable is defined');
} else {
console.log('Variable has NOT been defined');
}

Next I will talke about the ||, == and ===.

   var height;
height = 0;
if (height || height === 0) { // height == 0)
console.log('Variable is defined');
} else {
console.log('Variable has NOT been defined');
}

"||" means "or". Therefore, if will check the two conditions, if one of the condition is met, it will console.log 'Variable is defined'. Here, height === 0, so it returns Variable is defined.

Operation == is called "lenient" or "normal" equality. == only compares the value, it does not compair the type of value.

Operation === is called “strict” or “identical” equality. === compares the value and type. if var a=0, and int b=0, a=b returns false, because the type is different.

    console.log(23 == '23')  //--- ture
console.log(23 === '23') // ---false

Section 2.1: Falsy VSTruthy Value and == VS ===的更多相关文章

  1. Truthy Falsy

    https://developer.mozilla.org/zh-CN/docs/Glossary/Truthy falsy(虚值)是在 Boolean 上下文中已认定可转换为‘假‘的值. JavaS ...

  2. keil MDK error: L6236E: No section matches selector - no section 错误

    今天板子刚到,新建的第一个工程就报错了. .\Objects\cse.sct(7): error: L6236E: No section matches selector - no section t ...

  3. 【代码笔记】iOS-一个tableView,两个section

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  4. gcc/linux内核中likely、unlikely和__attribute__(section(""))属性

    查看linux内核源码,你会发现有很多if (likely(""))...及if (unlikely(""))...语句,这些语句其实是编译器的一种优化方式,具 ...

  5. <section> 标签

    最近正在学习html5,刚接触html5,感觉有点不适应,因为有一些标签改变了,特别是div, section article这三个标签,查了一些资料,也试着用html5和css3布局网页,稍微有点头 ...

  6. [ASP.NET MVC 小牛之路]12 - Section、Partial View 和 Child Action

    概括的讲,View中的内容可以分为静态和动态两部分.静态内容一般是html元素,而动态内容指的是在应用程序运行的时候动态创建的内容.给View添加动态内容的方式可归纳为下面几种: Inline cod ...

  7. $\LaTeX$笔记:Section 编号方式(数字、字母、罗马)&计数器计数形式修改

    $\LaTeX$系列根目录: Latex学习笔记-序 IEEE模板中Section的编号是罗马数字,要是改投其他刊物的话可能得用阿拉伯数字,所以可以在导言部分做如下修改(放在导言区宏包调用之后): \ ...

  8. [DOM Event Learning] Section 4 事件分发和DOM事件流

    [DOM Event Learning] Section 4 事件分发和DOM事件流 事件分发机制: event dispatch mechanism. 事件流(event flow)描述了事件对象在 ...

  9. [DOM Event Learning] Section 3 jQuery事件处理基础 on(), off()和one()方法使用

    [DOM Event Learning] Section 3 jQuery事件处理基础 on(),off()和one()方法使用   jQuery提供了简单的方法来向选择器(对应页面上的元素)绑定事件 ...

  10. [DOM Event Learning] Section 2 概念梳理 什么是事件 DOM Event

    [DOM Event Learning] Section 2 概念梳理 什么是事件 DOM Event   事件 事件(Event)是用来通知代码,一些有趣的事情发生了. 每一个Event都会被一个E ...

随机推荐

  1. DOM的操作(增删改查)

    操作DOM的核心就是增删改查 目录 一.节点创建型API 1.1 createElement 1.2 createTextNode 1.3 cloneNode 1.4 createDocumentFr ...

  2. 【推荐】MySQL数据库设计SQL规范

    1 命名规范 1.[强制]库名.表名.字段名必须使用小写字母并采用下划线分割,禁止拼音英文混用:(禁用-,-相当于运算符) 2.[建议]库名.表名.字段名在满足业务需求的条件下使用最小长度: 如inf ...

  3. MyBatis的使用六(解决字段名与成员名不一致)

    本文主要讲述mybatis如何解决mysql的字段名与java实体类的成员变量名称不一致. 一. 介绍实体类和数据表 1. 实体类Employee public class Employee { pr ...

  4. 遗传算法求TSP问题

    一.实验内容及目的 本实验以遗传算法为研究对象,分析了遗传算法的选择.交叉.变异过程,采用遗传算法设计并实现了商旅问题求解,解决了商旅问题求解最合适的路径,达到用遗传算法迭代求解的目的.选择.交叉.变 ...

  5. 为什么 TCP 建立连接需要三次握手(转载)

    为什么 TCP 建立连接需要三次握手(转载) 原文链接:https://draveness.me/whys-the-design-tcp-three-way-handshake/ TCP 协议是我们几 ...

  6. HTTP协议拓展

    本文详细介绍了 HTTPS 相较于 HTTP 更安全的原因,包括对称加密.非对称加密.完整性摘要.数字证书以及 SSL/TLS 握手等内容,图文并茂.理论与实战结合.建议收藏! 1. 不安全的 HTT ...

  7. MySQL-多表查询的两种方法、Navicat、python操作MySQL

    1.多表查询的两种方法 1.连表操作: 1.1:inner join:内连接,将两张表共同的部分连接起来生成一张新表.拼接顺序是把后面的表拼在前面的表,如果颠倒位置结果不同. select * fro ...

  8. DNA

    思路一: 这题需要桶+哈希(简化版像A 1  B  2 ......) 具体: 先把数据输入 再枚举可能的右端点,再由右端点得到左端点(l和r相差k) 在 l到r 区间内将这一段区间哈希成一个4进制数 ...

  9. *已解决 java写的简单验证码Servlet实践

    目的:java写的简单验证码Servlet实践 总结项目中遇到的问题 提供遇到同样问题的一些(菜鸟的)思路 (代码在最后~) 项目参考:https://www.itdaan.com/blog/2018 ...

  10. 五:spring boot

    五.spring boot 通过springboot可以快速的搭建一个基于ssm框架的Java application,简单配置,自动装配. JavaConfiguration用java类来替代xml ...