0% found this document useful (0 votes)
8 views2 pages

Convert string to Number

Uploaded by

bakhtawark085
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Convert string to Number

Uploaded by

bakhtawark085
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Convert string to Number

Here are 5 simple ways to convert a string into a number in JavaScript.

1. Using String(): Convert a number to a string using the String() function.

2. Using toString(): Use the number's .toString() method.

3. Using Template Literals: Wrap the number in ${} inside a string.

4. Using Concatenation: Add an empty string + "" to the number.

5. Using JSON.stringify(): Serialize the number using JSON.stringify().

Example Code:

let num = 123;

console.log(String(num)); // "123"

console.log(num.toString()); // "123"

console.log(`${num}`); // "123"

console.log(num + ""); // "123"

console.log(JSON.stringify(num)); // "123"

Convert Number to String

Here are 5 simple ways to convert a number into a string in JavaScript.

1. Using String(): Convert a number to a string using the String() function.

1. Using String(): Convert a number to a string using the String() function.

3. Using Template Literals: Wrap the number in ${} inside a string.

4. Using Concatenation: Add an empty string + "" to the number.

5. Using JSON.stringify(): Serialize the number using JSON.stringify().

Example Code:

let num = 123;

console.log(String(num)); // "123"

console.log(num.toString()); // "123"

console.log(`${num}`); // "123"

console.log(num + ""); // "123"


console.log(JSON.stringify(num)); // "123"

Created By : Muhammad Bakhtawar khan 03200276941

You might also like