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 ...
随机推荐
- flutter 1.升级2.X在模型类中序列化JSON报错Non-nullable instance field 'title' must be initialized.
flutter 1.升级2.X在模型类中序列化JSON报错 Non-nullable instance field 'title' must be initialized. Try adding an ...
- Pytest插件pytest-assume多重断言
Pytest插件pytest-assume多重断言 背景 import pytest def test_assume1(): assert 1 == 2 print('hello') assert 2 ...
- C# 如何部分加载“超大”解决方案中的部分项目
在有的特有的项目环境下,团队会将所有的项目使用同一个解决方案进行管理.这种方式方面了管理,但是却会导致解决方案变得非常庞大,导致加载时间过长.那么,如何部分加载解决方案中的部分项目呢?就让我们来借用微 ...
- C++ 地球人口承载力
题目描述 假设地球上的新生资源按恒定速度增长.照此测算,地球上现有资源加上新生资源可供 xx 亿人生活 aa 年,或供 yy 亿人生活 bb 年. 为了能够实现可持续发展,避免资源枯竭,地球最多能够养 ...
- JAVA虚拟机23---JAVA与线程
1 线程简介 线程是比进程更轻量级的调度执行单位,线程的引入,可以把一个进程的资源分配和执行调度分开,各个线程既可以共享进程资源(内存地址.文件I/O等),又可以独立调度 目前线程是Java里面进行处 ...
- maven打包失败 Cannot create resource output directory
转https://blog.csdn.net/wuyuanshun/article/details/103097447 maven clean后打包出现Cannot create resource o ...
- java7.14
- echarts在移动端上tooltip弹框点击空白不能关闭的问题解决方案
1.首先新建一个mixin.js文件 export const mixinAutoHideTooltip = { mounted() { this.mAutoHideTooltip(this.$el) ...
- (三) MdbCluster分布式内存数据库——节点状态变化及分片调整
(三) MdbCluster分布式内存数据库--节点状态变化及分片调整 上一篇: (二) MdbCluster分布式内存数据库--分布式架构 昨天我们在测试节点动态扩缩容时,发现了一个小bug ...
- debug补充、员工管理系统、字符编码、文件操作
一.debug补充 在当前行的代码左侧点击一下,会出现一个红点(打断点) 在代码编辑区域右键选择debug,不要在选择run 二.员工管理系统 # 创建大列表 staff_info_list = [] ...