1. Number in JavaScript In 0xa //corresponds to decimal 10 0b101 //corresponds to decimal 5 0o22 //corresponds to decimal 18 In 1/0 // Infinity
But the result of 0/0 is When a non-numeric string is converted to a numeric type, NaN is also returned, for example, You can use Number.isNaN(2) //false Number.isNaN('a') // true Number.isNan('2') //false Numeric value is a primitive type, and there is also a corresponding wrapper object n = new Number(10) n.valueOf() === 10 //true The value corresponding to the object n defined by the wrapper class is exactly equal to the original type value 10. 2. Math Object in Javascript Math.max gets the maximum value: let max = Math.max(1,2,3,4) console.log(max) //4 Math.min gets the minimum value: let min = Math.min(1,2,3,4) console.log(min) //1 If you are looking for the maximum and minimum values in an array, you can use the spread operator... to decompose the array into multiple parameter values. Math.max(...[1,2,3,4]) //4 Math.ceil rounds up: console.log(Math.ceil(2.3)) // 3 Math.floor rounds down: console.log(Math.floor(2.8)) // 2 Math.round rounds to the nearest integer: console.log(Math.round(2.5)) //3 console.log(Math.round(2.3)) //2
console.log(Math.random()) Randomly generate an integer between 0 and 10 let num = Math.ceil(Math.random()*10) console.log(num) Math.pow power: Math.pow(2, 10) //1024 This is the end of this article about the introduction of You may also be interested in:
|
<<: How to implement element floating and clear floating with CSS
>>: 50 Beautiful FLASH Website Design Examples
Install First you need to install Java and Scala,...
Problem Description In the recent background serv...
1.1 Introduction to iptables firewall Netfilter/I...
<table id=" <%=var1%>">, the...
Table of contents 1. Effect display 2. Enhanced v...
Table of Contents Introduction Synchronous Asynch...
As a front-end monkey, whether it is during an in...
This reading note mainly records the operations r...
There is a difference between src and href, and t...
1. Build a Docker environment 1. Create a Dockerf...
Recently, WeChat was forced by Apple to develop a...
Preface: This article is based on the experience ...
Preface Recently, I encountered a requirement. Du...
Table of contents Common payment methods in proje...
FastDFS & Nginx Integration: The tracker is c...