js小白操作:判断空值、判断数组最大最小值、判断map为空的情况、字符串转int
Js基础操作
项目要求开发一个微信小程序,我负责前端工作,这才开始真正接触前端语言。目前小程序已完成,决定从头梳理一些前端内容。本篇就从js语言基础的小trick开始~。
一、判断空值 undefined 和 null
js中使用typeof判断值的类型。
判断数据类型是否为undefined:
判断undefine时需要加上引号
var exp = undefined;
if (typeof(exp) === "undefined")
{
console.log("undefined");
}
// typeof后可以不跟括号
判断数据类型是否为null:
使用非其他类型来判断:
var exp = null;
if (!exp && typeof(exp)!==”undefined” && exp!==0)
{
console.