javascript基础语法

目录

1. 运算符

1.1. typeof

2. Math

2.1. Math.min 和 Math.max


1. 运算符

1.1. typeof

        当变量未定义,或变量已定义但未初始化时,typeof === undefined 判断有效

2. Math

2.1. Math.min 和 Math.max

  • 定义 

         js 函数Math.min 和 Math.max 来查找二维数组中的最小值和最大值

  • 问题1

       在小数组上工作正常但  在大数组时报“Maximum call stack size exceeded.”

       解决方案:

const arrayMinMax = (arr) => {
  // Math.min 和 Math.max 在大数组时报“Maximum call stack size exceeded.”
  return arr.reduce(
    ([min, max], val) => [Math.min(min, val), Math.max(max, val)],
    [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY]
  );
};

3. 数据类型

3.1. 空值和假值

  • undefined:表明变量没有初始化,即 “未定义”;
  • null:js 关键字,用于描述 “空值”,表示数字、字符串、对象是 “无值” 的,typeof 为 object,但不具备对象实例的属性与方法;
  • false、""、0:在 if 语句中表现为假值,他们都是有意义的数据,只是被用作空值或假值;
  • 判断数据是否为空
typeof(false) === 'boolean'
typeof(0) === 'number'
typeof("") === 'string'
typeof(null) === 'object'
typeof(undefined) === 'undefined'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值