This is the fifth day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021

We learned about the prefix operator/infix operator/special typeof in JavaScript. In this article, we learned about the Number function in JavaScript. A number that is not a numeric type

JavaScript Number(note the case of the first letter)

“Number” is capitalized, so this is a function that can be used to return a value of type Number.

Number | MDN: Number of JavaScript object is a can let you deal with the object of the numerical value of encapsulation. The Number object is created by the Number() constructor.

Number is an immutable base type. Returns “number”(lowercase) when using the previous special typeof.

Number Example

When creating an object in JavaScript, you can use the new keyword constructor, “new an object “. But the Number function is also an object when it comes out of new, but that’s usually not what we’re looking for.

// Both methods create a value and a value object, respectively
const needNumber = Number('621')
const newNumber = new Number('621')

// Let's look at the types of both:
typeof needNumber  /// --> 'number' is this

typeof newNumber /// --> 'object' 
/ /? We want a value, but we return an object, which is hard to deal with

// And the two guys are not equal
needNumber === newNumber  /// --> false
Copy the code

Number/role

We can almost understand the usage of Number. Let’s see again

Copy the code

Number(argument)

  • If the parameter cannot be converted to digital, it returns NaN | MDN.
  • In a non-constructor context (e.g., nonenew | MDNOperator),NumberCan be used to perform type conversions.

Where The value type is from

All numeric types are inherited from the number. prototype object. The modified Number constructor’s prototype object applies to all Number instances. Contains a list of methods on objects that are rarely used…