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. Docker 基础 - 2

    容器操作系统类型 Busybox 集成了一百多个最常用 Linux 命令和工具的软件工具箱. 包含cat echo grep find mount telnet 等 Busybox 是Linux 系统 ...

  2. python命令行参数argparse常用命令

    1.参数个数控制 parser.add_argument('-i', '--integers', nargs='?', const=100, type=int, help='input a numbe ...

  3. 一看就会的 Anaconda 搭建 OpenCV for Python 环境(全平台通用)

    前言 在学习 OpenCV 的时候,需要搭建 OpenCV 的环境并安装一些库,本文就准备了 OpenCV for Python,换而言之就是 OpenCV 的 python 的 API 接口.它拥有 ...

  4. 练习_请使用日期时间相关的API

    练习_请使用日期时间相关的API 练习:请使用日期时间相关的APi,计算出一个人已经出生了多少天.分析:1.使用scanner类中的方法next,获取出生日期2.使用DateFormat类中的方法pa ...

  5. MyBatis-Plus修改数据,会不会把其他字段置为null

    前两天在用MyBatis-Plus写了一张单表的增删改查,在写到修改的时候,就突然蹦出一个奇怪的想法. MyBatis-Plus的BaseMapper中有两个关于修改的方法.如下: int updat ...

  6. 重拾prometheus

    1.引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

  7. Docker安装SqlServer、Mysql、MariaDB

    一.Docker 安装SqlServer 说明 1. 拉取镜像 docker pull mcr.microsoft.com/mssql/server:2019-latest 2.运行 docker r ...

  8. 安装和配置Maven项目管理工具

    1.下载Maven工具包:https://maven.apache.org/download.cgi 2.解压apache-maven-3.8.4-bin.zip 3.修改apache-maven-3 ...

  9. Docker部署Nacos自动停止运行

    1.现象 使用docker部署的Nacos在运行一段时间后,就自动停止运行了. 查看docker运行容器,nacos停止了 2.解决 因为是学生购买的轻量级服务器,所以配置很低,出现这种问题我默认是内 ...

  10. STM32F0_HAL初始化系列:FLASH写入

    //读 read_temp = *(__IO uint32_t*)value_address; //写 static void flash_write(uint32_t address, uint32 ...