当前位置:网站首页>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
边栏推荐
- 飞机大战英雄出场加子弹实现
- Canvas draws graphics according to coordinate points
- MySQL 05 存储过程
- Intelligent insomnia therapeutic instrument product dlt8p68sa Jericho
- Nodejs 模板引擎ejs
- Multifunctional wireless remote control moxibustion instrument chip dltap703sd
- Collection of software design suggestions of "high cohesion and low coupling"
- Full automatic breast pump chip dltap703sd
- Mini washing machine touch chip dlt8ma12ts Jericho
- 浅谈JVM(面试常考)
猜你喜欢

USB rechargeable hand warmer chip dltap602sc Jericho

Whole body multifunctional massage instrument chip-dltap602sd

商品评论信息与评论信息分类

Low noise anion fan touch IC

JS to realize simple form verification and select all functions

Interviewer: what do you think is your biggest weakness?

Jianmu continuous integration platform v2.5.2 release

Personal Center - order business process

Hbuilder submission code

Uni app for wechat login (to be finished)
随机推荐
Valueerror: found input variables with inconsistent numbers of samples: [80019456, 26673152] [error reporting]
瑞吉外卖sql表
全身多功能按摩仪芯片-DLTAP602SD
Electric heating neck pillow chip-dltap703sc
JS tool - Cookie simple encapsulation
Mini washing machine touch chip dlt8ma12ts Jericho
Household mute mosquito repellent lamp chip-dltap703sd-jericho
JS to realize simple form verification and select all functions
SQL server stored procedures multi angle introduction suggestions collection
express
JDBC-MySql 02 数据访问和DAO模式
Typescript installation
Ruiji takeout SQL table
低噪负离子风扇触摸IC
The hero of the aircraft war comes out with bullets
Mode= "widthfix" attribute in image tag
JS to achieve smooth scrolling of pages or DOM elements
JDBC MySQL 01 JDBC operation MySQL (add, delete, modify and query)
Login page tablelayout
你想得到想不到的MySQL面试题都在这了(2022最新版)