JavaScript JS Tutorial JS Objects JS Functions JS Classes JS Async JS HTML DOM JS Browser BOM JS Web APIs JS AJAX JS JSON JS vs jQuery JS Graphics



JS Number Properties

JavaScript is a programming language that is used to create interactive web pages. One of the important features of JavaScript is its ability to work with numbers. JavaScript provides a number of properties that can be used to manipulate numbers. In this article, we will discuss the JS Number Properties and how they can be used in JavaScript programming.

Brief Explanation of JS Number Properties

JS Number Properties are the built-in properties of the Number object in JavaScript. These properties are used to manipulate numbers in JavaScript. Some of the commonly used JS Number Properties are:

  • Number.MAX_VALUE: This property returns the maximum value that can be represented by a number in JavaScript.
  • Number.MIN_VALUE: This property returns the minimum value that can be represented by a number in JavaScript.
  • Number.NaN: This property represents a value that is not a number.
  • Number.POSITIVE_INFINITY: This property represents the positive infinity value.
  • Number.NEGATIVE_INFINITY: This property represents the negative infinity value.

Code Examples

Let's take a look at some code examples to understand how JS Number Properties can be used in JavaScript programming:

Example 1: Using Number.MAX_VALUE

The following code demonstrates how to use the Number.MAX_VALUE property:

  
    var max = Number.MAX_VALUE;
    console.log(max); // Output: 1.7976931348623157e+308
  

Example 2: Using Number.MIN_VALUE

The following code demonstrates how to use the Number.MIN_VALUE property:

  
    var min = Number.MIN_VALUE;
    console.log(min); // Output: 5e-324
  

Example 3: Using Number.NaN

The following code demonstrates how to use the Number.NaN property:

  
    var x = "Hello";
    var y = Number(x);
    console.log(y); // Output: NaN
  

Example 4: Using Number.POSITIVE_INFINITY

The following code demonstrates how to use the Number.POSITIVE_INFINITY property:

  
    var x = 1 / 0;
    console.log(x); // Output: Infinity
  

Example 5: Using Number.NEGATIVE_INFINITY

The following code demonstrates how to use the Number.NEGATIVE_INFINITY property:

  
    var x = -1 / 0;
    console.log(x); // Output: -Infinity
  

Conclusion

JS Number Properties are an important feature of JavaScript programming. They provide a way to manipulate numbers in JavaScript. By using these properties, you can perform various operations on numbers and make your JavaScript code more efficient and effective.

References

Activity