
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How -Infinity is converted to String in JavaScript?
We all know that string is one of the primitive data types in JavaScript. JavaScript allows us to do some operations on strings like finding characters in the string, changing all characters into lowercase or into uppercase, concatenating with other strings, replacing with other strings, searching character(s) or word(s) from string, etc.
We denote string in single quotations or in double quotations. typeof string variable will be a string.
Syntax
Syntax for String() method is, like
String(value)
value is required. value is JavaScript value. String() method returns a value i.e. as a string. String() method introduced in ES1 and it is fully supported by all browsers.
Steps to convert -Infinity to String
STEP 1 - Declare a variable and assign -Infinity to it.
STEP 2 - Convert -Infinity to string using the String() method.
STEP 3 - Display the result.
Let's look at examples for converting value into string.
Example
Converting -Infinity to String
In the below example, we convert "–Infinity" to string using the String() method in JavaScript.
<!DOCTYPE html> <html> <body> <h2>Converting - Infinfity to String</h2> <p>value and typeof value : <span id="value"></span> </p> <p>value and typeof value : <span id="result"></span> </p> <script> var value = - Infinity; document.getElementById('value').innerHTML = value + " and " + typeof value; var str = String(value); document.getElementById('result').innerHTML = str + " and " + typeof str; </script> </body> </html>
Here, we can see after the String() method, the typeof value changed from number to string.
Example
Converting Infinity to String
We can also convert "Infinity" to string. Let's look into an example
<!DOCTYPE html> <html> <body> <h2>Converting Infinity to String</h2> <p>value and typeof value : <span id="value"></span> </p> <p>value and typeof value : <span id="result"></span> </p> <script> var value = Infinity; document.getElementById('value').innerHTML = value + " and " + typeof value; value = String(value); document.getElementById('result').innerHTML = value + " and " + typeof value; </script> </body> </html>
Example
Using the toString() method
Note that the String() method and toString() method returns the same result for any value. Here, toString() is one of the methods of JS string. Let's look at an example with toString() also.
<!DOCTYPE html> <html> <body> <h2>Converting -Infinity to String</h2> <p>value and typeof value : <span id="value"></span> </p> <p>value and typeof value : <span id="result"></span> </p> <script> var value = -Infinity; document.getElementById('value').innerHTML = value + " and " + typeof value; value = value.toString(); document.getElementById('result').innerHTML = value + " and " + typeof value; </script> </body> </html>
In this tutorial, we have seen converting values -Infinity into String in JavaScript. Hope this gives some knowledge on converting -Infinity into string.
- Related Articles
- How Is Infinity converted to String in JavaScript?
- How Is Infinity converted to Number in JavaScript?
- How -Infinity is converted to Number in JavaScript?
- How -Infinity is converted to Boolean in JavaScript?
- How Is Infinity converted to Boolean in JavaScript?
- How [ ] is converted to String in JavaScript?
- How null is converted to String in JavaScript?
- How is NaN converted to String in JavaScript?
- What will happen when { } is converted to String in JavaScript?
- How [ ] is converted to Number in JavaScript?
- How [ ] is converted to Boolean in JavaScript?
- How null is converted to Number in JavaScript?
- How null is converted to Boolean in JavaScript?
- How is NaN converted to Boolean in JavaScript?
- How is NaN converted to Number in JavaScript?
