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 ...
随机推荐
- Linux c 获取U盘挂载路径
思路: 1.执行df -h 找到 带mnt的行.将结果存入一个文件中. system("df -h |grep mnt >./extendevinfo.txt"); 也可以直 ...
- 创建进程的多种方式、多进程实现TCP并发等知识点
创建进程的多种方式.多进程实现TCP并发等知识点 一.同步与异步 1.提交完成任务之后原地等待任务的返回结果,期间不做任何事 2.提交完任务之后不愿原地等待任务的返回结果,直接去做其他事情,有结果自动 ...
- QtCharts模块勾画折线和曲线图
QtCharts画线图主要三个部分组成 QLIneSeries或QSplineSeries用于保存联系的坐标位置数据,QChart用于管理图像显示,例如图例,坐标主题等,QChartView则用于显示 ...
- 【LeetCode】三数之和+四数之和(双指针)
之所以放在一起是因为,"四数之和"的解题方法基本与"三数之和"一致 由此我们可以推出n数之和的解法 本质上,我们只是使用双指针的方法降低此类问题的时间复杂度 当 ...
- Kubernetes环境cert-manager部署与应用
本作品由Galen Suen采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可.由原作者转载自个人站点. 概述 本文用于整理基于Kubernetes环境的cert-manager部 ...
- visual studio(vs2017、vs2019)离线安装包下载、制作
一.下载安装引导程序(以vs-professional-2019为例) https://aka.ms/vs/16/release/vs_professional.exe 二.在引导程序目录打开cmd命 ...
- 树莓派4B—LCD触摸屏和硬件串口配置
1.LCD触摸屏直接下载官网驱动,这里选用的是3.5寸显示屏,解压后直接运行 sudo ./LCD35-show 然后重启. 注意:一定要先安装LCD驱动,因为安装驱动会修改/boot/config. ...
- C++练习3 定义带默认值的参数
通过void func 定义函数的默认值和其可以容纳多少个实参 1 #include <iostream> 2 using namespace std; 3 void func(int a ...
- GoAccess实现请求监
GoAccess实现请求监控 简介 GoAccess是一款开源的实时web日志分析器和交互式查看器,用于可视化查看HTTP统计信息,可以系统的终端上运行,也可以通过浏览器运行: 本文通过使用GoAcc ...
- 【SDOI2015】寻宝游戏
代码 (树链剖分) #include<cstdio> #include<set> using namespace std; typedef long long LL; cons ...