当前位置:网站首页>Extension of ES6 value
Extension of ES6 value
2022-07-27 18:58:00 【venture to ask】
1、 Binary and octal representations
ES6 Provides a new way to write binary and octal values , Use prefixes, respectively 0b( or 0B) and 0o( or 0O) Express .
console.log(0b111110111 === 503)//true
console.log(0o767 === 503)//truefrom ES5 Start , In the strict model , Octal no longer allows prefixes 0 Express ,ES6 To be more specific , To use a prefix 0o Express .
Nonstrict mode
(function () {
console.log(0o11 === 011);
})() //trueStrict mode
(function(){
'use strict';
console.log(0o11 === 011);
})() // Uncaught SyntaxError: Octal literals are not allowed in strict mode.If you want to 0b and 0o The string value of the prefix is converted to decimal , To use Number Method .
Number('0b111') // 7
Number('0o10') // 82、 Common expansion methods of numerical values
Reference to the method of numerical expansion :http://caibaojian.com/es6/string.html
2.1 Number.isNaN() Used to check whether a value is NaN
The difference from traditional methods is that there is no implicit conversion
Number.isNaN(NaN) // true
Number.isNaN(15) // false
Number.isNaN('15') // false
Number.isNaN(true) // false
Number.isNaN(9/NaN) // true
Number.isNaN('true'/0) // true
Number.isNaN('true'/'true') // true2.2、ES6 Take a global approach parseInt() and parseFloat(), Migration to Number The above object , The behavior remains completely the same
// ES5 Writing
parseInt('12.34') // 12
parseFloat('123.45#') // 123.45
// ES6 Writing
Number.parseInt('12.34') // 12
Number.parseFloat('123.45#') // 123.45The purpose of this , Is to gradually reduce the overall approach , Make the language modular step by step
2.3、Number.isInteger() Used to determine whether a value is an integer
stay JavaScript Inside , Integers and floating-point numbers are stored in the same way , therefore 3 and 3.0 Be treated as the same value
Number.isInteger(25) // true
Number.isInteger(25.0) // true
Number.isInteger(25.1) // false
Number.isInteger("15") // false
Number.isInteger(true) // false3、Math Method extension
3.1、Math.trunc Method is used to remove the decimal part of a number , Returns the integer part , There will be implicit conversions
Math.trunc(4.1) // 4
Math.trunc(4.9) // 4
Math.trunc(-4.1) // -4
Math.trunc(-4.9) // -4
Math.trunc(-0.1234) // -03.2、Math.sign Method is used to determine whether a number is positive 、 negative 、 It's still zero .
- The parameter is a positive number , return +1;
- The argument is negative , return -1;
- Parameter is 0, return 0;
- Parameter is -0, return -0;
- Other values , return NaN.
Math.sign(-5) // -1
Math.sign(5) // +1
Math.sign(0) // +0
Math.sign(-0) // -0
Math.sign(NaN) // NaN
Math.sign('foo'); // NaN
Math.sign(); // NaN
边栏推荐
- Aircraft collision detection
- js实现简易表单验证与全选功能
- Multifunctional wireless remote control moxibustion instrument chip dltap703sd
- MySQL 03 advanced query (I)
- 百度地图鹰眼轨迹服务
- Low noise anion fan touch IC
- LeetCode 刷题 第三天
- Leetcode first day of question brushing
- TypeError: conv2d(): argument ‘padding‘ (position 5) must be tuple of ints, not str【报错】
- Uploading and downloading of files
猜你喜欢

How to realize the full-text content retrieval of word, PDF and txt files?

I'm stupid. When completable future is used with openfegin, it even reports an error

MySQL 04 advanced query (II)

订单超时取消 及 按类别查询商品

What does the number of network request interface layers (2/3 layers) mean

Bathroom with demister vanity mirror touch chip-dlt8t10s

Jianmu continuous integration platform v2.5.2 release

npm 基本使用

Netred RGB mirror light touch chip-dlt8s15b-jericho

MySQL 03 advanced query (I)
随机推荐
Interviewer: what do you think is your biggest weakness?
TypeError: conv2d(): argument ‘padding‘ (position 5) must be tuple of ints, not str【报错】
npm 基本使用
JDBC-MySql 01 JDBC操作MySql(增删改查)
Infrared hyperspectral survey
连接查询和子查询
Baidu map eagle eye track service
你想得到想不到的MySQL面试题都在这了(2022最新版)
`this.$emit` 子组件给父组件传递多个参数
idea 2020.1社区版下载体验
Hash、Set、List、Zset、BitMap、Scan
瑞吉外卖sql表
LeetCode 刷题 第三天
npm、cnpm 淘宝镜像
JS中的数组与对象
浅谈JVM(面试常考)
What should I do if MySQL master-slave replication data is inconsistent?
Led learning eye protection table lamp touch chip-dlt8t10s-jericho
C file and folder input / output stream code
Nodejs 模板引擎ejs