js中使用0 “” null undefined {}需要注意
注意:在js中0为空(false) ,代表空的还有“”,null ,undefined;
如果做判断if(!上面的四种值);返回均为false
console.log(!null);// true
console.log(!0);//true
console.log(!"");// true
console.log(!undefined);// true
console.log(0=="");//true
console.log(0==" ");// true
console.log(undefined==null);// true
----------------------------------------------
var val=0; //undefined
console.log(val=='');//true
var val='0'; //undefined
console.log(val=='');//false
console.log(0==undefined);//false
console.log('0'==undefined);//false
----------------------------------------------
在对接收的参数进行判断时一定注意 :当参数取值既有0也有‘’时要小心区分
-----------------------------------------------
console.log(typeof null) //object
console.log(typeof {}) //object
console.log(null == {}) //false var tem1 = null;
var tem2 = {};
console.log(tem2.length); //undefined
console.log(tem1.length); //报错Cannot read property 'length' of null 如何判断是否为空对象。
console.log(tem1==null);//true,因此可以用该方法判断为null对象
console.log(tem2=={});//false,不能这样判断{}对象 应该用下面的方式
console.log(JSON.stringify(tem2) == "{}")//ture -------------------------------------------
js中使用0 “” null undefined {}需要注意的更多相关文章
- 【转发】JS中如何判断null/ undefined/IsNull
以下是不正确的方法:var exp = null;if (exp == null){ alert("is null");}exp 为 undefined 时,也会得到与 null ...
- js中NAN、NULL、undefined的区别
NaN:保留字(表明数据类型不是数字) undefined:对象属性或方法不存在,或声明了变量但从未赋值.即当你使用了对象未定的属性或者未定义的方法时或当你声明一个变量,但你确从未对其进行赋值,便对其 ...
- 160304-02、JS 中如何判断null 和undefined
JavaScript 中有两个特殊数据类型:undefined 和 null,下节介绍了 null 的判断,下面谈谈 undefined 的判断. 以下是不正确的用法: var exp = undef ...
- JS中原始类型Null和Undefined
Undefined类型只有一个值,即undefined.当声明的变量还未被初始化时,变量的默认值为undefined.Null类型也只有一个值,即null.null用来表示尚未存在的对象,常用来表示函 ...
- 分享一个在js中判断数据是undefined,NaN,null,的技巧
教大家如何在js中判断一个值是否是undefined,null,NaN,以及如何单独判断 平常开发过程中大家可能遇到一种问题,就是取页面某个值的时候获取不到这个var就是undefined了,如果是数 ...
- 你所不知道的 JS: null , undefined, NaN, true==1=="1",false==0=="",null== undefined
1 1 1 === 全相等(全部相等) == 值相等(部分相等) demo: var x=0; undefined var y=false; undefined if(x===y){ console ...
- JS中如何判断null、undefined与NaN
1.判断undefined: <span style="font-size: small;">var tmp = undefined; if (typeof(tmp) ...
- JS去除对象或数组中的空值('',null,undefined,[],{})
javascript去掉对象或数组中的'',null,undefined,[],{}.思路就是创建一个新的空对象,然后对传入的对象进行遍历,只把符合条件的属性返回,保留有效值,然后就相当于把空值去掉了 ...
- 0,null,undefined,[],{},'',false之间的关系
0与一些虚值的比较: 0与false 0==false true 0与'': =='' true 0与[]: ==[] true 0与NaN: 0==NaN false 0与undefined 0== ...
随机推荐
- 下载pywinauto
1.下载pywinauto 链接:http://pywinauto.github.io/ 2.将安装包放到D:python36\script,进入pywinauto目录,按shift+右键,进入命令窗 ...
- wx 文件编辑框
# -*- coding: utf- -*- import wx import os class my_frame(wx.Frame): """This is a sim ...
- 20165236实验一 Java开发环境的熟悉
课程:Java 姓名:郭金涛 学号:20165236 实验日期:2018/04/01 指导老师:娄嘉鹏 实验名称:Java开发环境的熟悉 实验要求: 1. 建立“自 ...
- 关于vue中eslint规范报错问题
/* global _ */这样 页面_就不会报错了
- python按修改时间顺序排列文件
import os def sort_file_by_time(file_path): files = os.listdir(file_path) if not files: return else: ...
- Spark中的partition和block的关系
hdfs中的block是分布式存储的最小单元,类似于盛放文件的盒子,一个文件可能要占多个盒子,但一个盒子里的内容只可能来自同一份文件.假设block设置为128M,你的文件是250M,那么这份文件占3 ...
- [Leetcode] Template to rotate matrix
Rotate the image by 90 degrees (clockwise). Given input matrix = [ [1,2,3,4], [5,6,7,8], [9,10,11,12 ...
- 产品设计教程:利用“系列位置效应”优化UI
任何博得人们喜欢的产品都在一定程度上契合了用户的心理需求.设计和心理学息息相关,掌握一些基本心理学知识,设计师的作品更能在潜意识中抓住用户的心. 系列位置效应 “系列位置效应”(The Serial ...
- 关于RBAC的文章
权限系统与RBAC模型概述 RBAC权限管理模型 摘自慕课网的RBAC
- cocos2dx C++ imageView(图片/九宫格)相关属性大全
ImageView * imageView = ImageView::create("cocosui/ccicon.png");//新建图片 imageView->setSc ...