Section 2.1: Falsy VSTruthy Value and == VS ===
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 ===的更多相关文章
- Truthy Falsy
https://developer.mozilla.org/zh-CN/docs/Glossary/Truthy falsy(虚值)是在 Boolean 上下文中已认定可转换为‘假‘的值. JavaS ...
- keil MDK error: L6236E: No section matches selector - no section 错误
今天板子刚到,新建的第一个工程就报错了. .\Objects\cse.sct(7): error: L6236E: No section matches selector - no section t ...
- 【代码笔记】iOS-一个tableView,两个section
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- gcc/linux内核中likely、unlikely和__attribute__(section(""))属性
查看linux内核源码,你会发现有很多if (likely(""))...及if (unlikely(""))...语句,这些语句其实是编译器的一种优化方式,具 ...
- <section> 标签
最近正在学习html5,刚接触html5,感觉有点不适应,因为有一些标签改变了,特别是div, section article这三个标签,查了一些资料,也试着用html5和css3布局网页,稍微有点头 ...
- [ASP.NET MVC 小牛之路]12 - Section、Partial View 和 Child Action
概括的讲,View中的内容可以分为静态和动态两部分.静态内容一般是html元素,而动态内容指的是在应用程序运行的时候动态创建的内容.给View添加动态内容的方式可归纳为下面几种: Inline cod ...
- $\LaTeX$笔记:Section 编号方式(数字、字母、罗马)&计数器计数形式修改
$\LaTeX$系列根目录: Latex学习笔记-序 IEEE模板中Section的编号是罗马数字,要是改投其他刊物的话可能得用阿拉伯数字,所以可以在导言部分做如下修改(放在导言区宏包调用之后): \ ...
- [DOM Event Learning] Section 4 事件分发和DOM事件流
[DOM Event Learning] Section 4 事件分发和DOM事件流 事件分发机制: event dispatch mechanism. 事件流(event flow)描述了事件对象在 ...
- [DOM Event Learning] Section 3 jQuery事件处理基础 on(), off()和one()方法使用
[DOM Event Learning] Section 3 jQuery事件处理基础 on(),off()和one()方法使用 jQuery提供了简单的方法来向选择器(对应页面上的元素)绑定事件 ...
- [DOM Event Learning] Section 2 概念梳理 什么是事件 DOM Event
[DOM Event Learning] Section 2 概念梳理 什么是事件 DOM Event 事件 事件(Event)是用来通知代码,一些有趣的事情发生了. 每一个Event都会被一个E ...
随机推荐
- (14)go-micro微服务服务层Handle开发
目录 一 Handle层开发功能说明 需要完成的服务开发功能: 从哪找需要开发的功能 二 代码编写 三 最后 一 Handle层开发功能说明 需要完成的服务开发功能: 登录 注册 查询用户信息 修改信 ...
- 笔记本USB接口案例_分析-笔记本USB接口案例_实现
笔记本USB接口案例_分析 笔记本电脑(laptop)通常具备使用USB设备的功能.在生产时,笔记本都预留了可以插入USB设备的USB接口, 但具体是什么USB设备,笔记本厂商并不关心,只要符合USB ...
- Dubbo 入门系列之基于 Dubbo API 开发微服务应用
目标 从零上手开发基于 Dubbo 的微服务 难度 低 环境要求 系统:Windows.Linux.MacOS JDK 8 及以上(推荐使用 JDK17) Git IntelliJ IDEA(可选) ...
- drf-day2——restful规范、序列化反序列化、基于django编写五个原生接口、drf介绍和快速使用、cbv源码分析
目录 一.restful规范(重要,不难) 概念 十个规范 二.序列化反序列化 三.基于django原生编写5个接口 四.drf介绍和快速使用 概念 安装 代码 五.cbv源码分析 六.作业 1.使用 ...
- 【一句话】Java8后abstract class和interface的区别
首先一句话: Java8后(1)interface支持default和static方法有实现,abstract class依然是抽象方法和非抽象方法,(2)可同时实现多个interface,(3)但成 ...
- JAVA虚拟机08--垃圾回收--HotSpot的算法实现细节
1 stop the world 2 减少stop the world的时间-OopMap 3 OopMap数据结构的维护-安全点-安全区域 3.1安全点 3.2在垃圾回收时如何让所有线程到达最近的安 ...
- Typora下载与安装 0.9.75版本
Typora下载与安装 效果图 一.简介 一款 Markdown 编辑器和阅读器 (0.9.75 版本 不需购买) 二.下载 下载地址:Typora 三.安装 1.下载文件后双击安装 2. 选择存放的 ...
- MySQL中的函数使用
有三张表,学生表(t_student),班级表(t_class),成绩表(t_grade),三张表的字段设计如下 查询大竹 ...
- Python装饰器实例讲解(三)
Python装饰器实例讲解(三) 本文多参考<流畅的python>,在此基础上增加了一些实例便于理解 姊妹篇 Python装饰器实例讲解(一),让你简单的会用 Python装饰器实例讲解( ...
- The Missing Semester - 第二讲 学习笔记
第二讲 Shell 工具和脚本 课程视频地址: https://www.bilibili.com/video/BV1Vv411v7FR 本机学习使用平台:虚拟机ubuntu18.04.6 主题一:Sh ...