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. 全志R528 系统繁忙时触摸屏I2C报错问题。

    最近调试项目时遇到一个奇怪的问题. 当linux 系统繁忙时(开机,关机或APP繁忙等情况),此时按下触摸屏后, I2C总线就会报错,TP读数据失败,之后内存报错,重启. root@TinaLinux ...

  2. Ubuntu 22.04 BigSur 美化

    安装 tweaks sudo apt update && sudo apt upgrade sudo apt install gnome-tweaks gnome-shell-exte ...

  3. echarts图表配置

    1.柱状图 option = { xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] ...

  4. MyBatis使用四(查询详解)

    本文主要讲述如何在mybatis中进行查询操作[详解] 一. 查询User对象 1.查询单个对象User SelectUser接口声明如下 // 主要条件是使用id public interface ...

  5. Java CompletableFuture 异步超时实现探索

    作者:京东科技 张天赐 前言 JDK 8 是一次重大的版本升级,新增了非常多的特性,其中之一便是 CompletableFuture.自此从 JDK 层面真正意义上的支持了基于事件的异步编程范式,弥补 ...

  6. Swagger2多包扫描

    package com.xf.config; import org.springframework.context.annotation.Bean; import org.springframewor ...

  7. LeetCode_单周赛_328

    6291. 数组元素和与数字和的绝对差 代码 模拟即可 class Solution { public int differenceOfSum(int[] nums) { int ans = 0; i ...

  8. Vue22 VueCli 脚手架

    1 简介 CLI 是 Command-Line Interface, 翻译为命令行界面, 但是俗称脚手架 Vue CLI是一个官方发布 vue.js 项目脚手架 使用 vue-cli 可以快速搭建 V ...

  9. Element-Ui表单移除校验clearValidate和resetFields

    添加和修改公用一个弹窗,点击添加弹窗后,如果没移除表单校验的话,再点击修改弹窗时校验就会被记住,所以需要移除校验,但在清空表单校验时会报如下错误: 那么,你只需要加上这段话即可 this.$nextT ...

  10. DrCush_082020_血清阴性RA确诊延迟

    转自Dr Jack Cush的Twitter (2020-08-20) 梅奥诊所:血清阴性RA的诊断存在延迟-血清阴性的首次关节肿胀距RA确诊为187天,而血清阳性者则为11天(P <.001) ...