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 ...
随机推荐
- vue3实现一个抽奖小项目
前言 在公司年会期间我做了个抽奖小项目,我把它分享出来,有用得着的可以看下. 浏览链接:http://xisite.top/original/luck-draw/index.html 项目链接:htt ...
- 【Linux技术专题系列】「必备基础知识」一起探索和实践sftp配置之密钥方式登录
FTP服务-vsftp协议实现 我们常用的是FTP协议,主要是通过VSFTP是一个基于GPL发布的类Unix系统上使用的FTP服务器软件,它的全称是Very Secure FTP 从此名称可以看出来, ...
- Unity之UGUI鼠标进入离开&&拖拽实现
Unity之UGUI鼠标进入离开&&拖拽实现 前言: __小黑最近在写项目的时候就有个疑惑,UGUI中的Button组件,他的点击事件是怎么实现的!?我们自己能不能写一个!?之后在项目 ...
- 【学习笔记】C++ 常量折叠原理和验证
以下的代码很有意思,在相同时刻,相同的内存地址,数据居然会不一样. #include <iostream> int main(void) { const int const_val = 3 ...
- React Refs-知识点整理记录
一.Refs的作用 通过Refs,可以访问到 1. DOM节点. 2. render方法中创建的React元素.(class组件的实例) 二.访问节点或者实例有什么用?为什么要使用Refs来访问? 访 ...
- 微服务学习计划——SpringCloud
微服务学习计划--SpringCloud 在学习并掌握了众多基础框架之后,我们的项目繁杂且难以掌握,那么我们就需要开启一门新的课程,也就是我们常说的微服务架构 随着互联网行业的发展,对服务的要求也越来 ...
- Android面试-字节一面
距离上次跳槽已经过了3年多,突然看到字节的HR来捞.想着自己好久没面了,就打算去试试看. 0. 准备 视频面试,不用去现场真的太赞了.由于项目比较忙,自己又不是特别想跳槽,所以没怎么准备.面试当天看了 ...
- 一个javaweb的项目的思路
马上就要期中考试了,把最近靠自己学的知识总结一下(自己学的),以下为eclipse的一个界面 可以看出,有很多内容.首先,有好几个包,Bean,Dao,servlet,service,Util,Uti ...
- 鼎阳SDS6204长波形读取的潜力挖掘及上海光源测试
https://blog.csdn.net/weixin_43767046/category_11089525.html 上学期我搭建起来的逐束团3维质心位置测量系统一直是获取500us长的一 ...
- MySQL索引相关知识学习心得
你知道的越多,你不知道的也就越多 -- 芝诺曾 一.MySQL索引学习 MySQl主要有两种类型的索引:哈希索引.B+树索引 1.哈希索引 哈希索引可以以O(1)的时间复杂度进行查找,但是这样查找导致 ...