Truthy and Falsy Values and Equality Operators
最近在学习JS. 有一些概念还希望跟大家分享出来
Truthy and Falsy Values
Falsy Values: undefined, null, 0, '', NaN(not a number)
Truthy values: NOT falsy values
var height;
height = 0; // return else value var name;
name = ''; // return else value var testNumber;
testNumber = 1; // return if value if (height) {
console.log("Variable is defined");
} else {
console.log("Variable has NOT been defined");
}
Equality Operators
== 和 === 的区别
=== 是必须type 相同的情况下value 相同.
e.g.
var number1;
number1 = 1; var number2;
number2 = 1; var isNumberSame;
number1 === number2 ? isNumberSame = true : isNumberSame = false;
console.log("Is 2 numbers same? " + isNumberSame)
== 不考虑type的情况下只考虑value相同.
e.g.
var number1;
number1 = 1; var number2;
number2 = 1; var string1;
string1 = "1"; // var isNumberSame;
// number1 === number2 ? isNumberSame = true : isNumberSame = false;
// console.log("Is 2 numbers same? " + isNumberSame) if(number1 == string1)
{
console.log("The == operator does type ")
}
else{
console.log("Error")
}
Truthy and Falsy Values and Equality Operators的更多相关文章
- 小tips:JS的Truthy和Falsy(真值与假值)
前言 Truthy 不等于 ture,他是指是在Boolean上下文中转换后的值为真的值.我的理解是,在javascript中所有表达式为true的值.同理Falsy指的是在javascript中所有 ...
- [转] JavaScript中的Truthy和Falsy介绍
[From] http://www.jb51.net/article/59285.htm 与大多数编程语言一样,JavaScript中存在boolean类型,以供逻辑判断使用.不过,和很多其它编程语言 ...
- 关于truthy 和 falsy
一,强制类型转换 JavaScript 在需要用到布尔类型值的上下文中使用强制类型转换(Type Conversion )将值转换为布尔值,比如:在条件语句或者循环语句中 一,truthy 在java ...
- JavaScript中的Truthy和Falsy
JavaScript中存在Truthy值和Falsy值的概念 — 除了boolean值true.false外,所有类型的JavaScript值均可用于逻辑判断,其规则如下: 1.所有的Falsy值,当 ...
- 【转】The && and || Operator in JavaScript
原文: https://blog.mariusschulz.com/2016/05/25/the-andand-and-operator-in-javascript The && an ...
- New for ASP.NET Web Pages: Conditional attributes
from:http://www.mikepope.com/blog/AddComment.aspx?blogid=2353 March 01, 2012 The beta release of ASP ...
- comparison of floating point numbers with equality operator. possible loss of precision while rounding values
double值由外部传入 private void Compare(double value) { string text; ) //小数位后保留2位 { //小数点后保留2位小数 text = st ...
- Core Java Volume I — 3.5. Operators
3.5. OperatorsThe usual arithmetic operators +, -, *, / are used in Java for addition, subtraction, ...
- Eloquent JavaScript #01# values
When action grows unprofitable, gather information; when information grows unprofitable, sleep. ...
随机推荐
- angular2架构详解
参考 http://codin.im/2016/09/18/angular2-architecture-intro/ http://www.tuicool.com/articles/EvEZjmZ ...
- CodeForces - 779D
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But i ...
- L258 技术转让
We will inform you of the weight, measurements, number of cases, cost of the drawings and other docu ...
- date简述
Date 定义时间和日期的类 java.util.Date 1s=1000ms; 时间的原点:公元1970年1月1日 00点00分00秒: public class DateDemo { publ ...
- python day03--字符串
一.字符串 1.索引 s1 = "python最牛B" S1[0]第0个,从零开始算 s1[8]“B” 2.切片 语法: str[start: end]规则: 顾头不顾腚, 从st ...
- ecmall 基础类分析
class ECBaseApp,继承自class BaseApp,是includes/ecapp.base.php文件. 该类是一个非常重要的类,他是各个APP的应用的基础继承类.处理相关的基础应用. ...
- Spring Boot 揭秘与实战(二) 数据缓存篇 - Guava Cache
文章目录 1. Guava Cache 集成 2. 个性化配置 3. 源代码 本文,讲解 Spring Boot 如何集成 Guava Cache,实现缓存. 在阅读「Spring Boot 揭秘与实 ...
- [转]lua数据结构--闭包
前面几篇文章已经说明了Lua里面很常用的几个数据结构,这次要分享的也是常用的数据结构之一 – 函数的结构.函数在Lua里也是一种变量,但是它却很特殊,能存储执行语句和被执行,本章主要描述Lua是怎么实 ...
- Java 经典面试题 —— 性能
1. 性能 String.StringBuffer 与 StringBuilder 两个字符串相加,str1+str2,相当于执行: StringBuilder strBuilder1 = new S ...
- nginx php
server { listen 443; server_name www.awkj.com; ssl on; ssl_certificate cert/214683879970617.pem; ssl ...