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 ...
随机推荐
- py教学之字典
字典简介 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值 key=>value 对用冒号 : 分割,每个对之间用逗号(,)分割,整个字典包括在花括号 {} 中 ,格式如下所示: ...
- .Net 7 托管Main入口的四种类型
前言: 按照CLR的规则,C#托管Main入口其实有四种写法. 写法 第一种:最常见的,也是VS默认的,返回值void,带一个参数 static void Main(string[] args) { ...
- Django-Ajax、form组件
1.Ajax 1.AJAX:不是新的编程语言,而是一种使用现有标准的新方法,我们目前学习的是jQuery版本.特点:异步提交,局部刷新. 2.AJAX 最大的优点是在不重新加载整个页面的情况下,可以与 ...
- 计算机网络12 TCP
1 TCP简介 CP的全称是Transmission Control Protocol,即传输控制协议,TCP工作在传输层上 其职责是:实现主机间进程到进程的通信,其次还需要保证可靠性(不是安全性,换 ...
- Vue12 监视属性
1 简介 所谓监听就是对内置对象的状态或者属性变化进行监听并且做出反应的响应,监听属性,意思就是可以监视其他数据的变化 2 使用 使用watch配置项,在配置项里面写上要监视的属性,每次属性值的变化都 ...
- Windows Server 2016 安装AD和Exchange
一.AD虚拟机操作 1.安装net framework 4.8 下载链接:https://dotnet.microsoft.com/download/dotnet-framework/net48 安装 ...
- 随机森林RF模型超参数的优化:Python实现
本文介绍基于Python的随机森林(Random Forest,RF)回归代码,以及模型超参数(包括决策树个数与最大深度.最小分离样本数.最小叶子节点样本数.最大分离特征数等)自动优化的代码. ...
- 【JS入门小游戏】01-骰子游戏
01-骰子游戏 游戏出自Udemy的JS课程中提到的一个游戏,课程主要是对JS部分进行详细的从0开始的讲解,本篇文章是对整个游戏的分析,包括HTMK,CSS和JS,也主要对JS进行刨析. 游戏链接:h ...
- JZOJ 3167.查税
\(\text{Solution}\) 记 \(k\) 这个办公室相关属性有 \(t,z,s\) 对于以后的某一天 \(T\),其账户余额为 \((T-t)z+s\) 要最大化这东西,不妨另 \(b= ...
- HTML5基本网页结构以及标签的改变
转载csdn:https://blog.csdn.net/z983002710/article/details/76300327