angular int to string 1

angular int to string

var x = 3,
    toString = x.toString(),
    toConcat = x + "";

Here is what the above code is Doing:
1. Declare a variable x and assign it the value 3.
2. Declare a variable toString and assign it the result of calling the toString() method on x.
3. Declare a variable toConcat and assign it the result of adding an empty string to x.

The toString() method is a built-in JavaScript method that converts a value to a string.

The + operator is also used to add numbers, but when it is used on one number and one string, it will add the numbers together as if they were both numbers.

The result of adding a number and a string is always a string.

In the example above, toString and toConcat are assigned the same value, but toString is a string and toConcat is a number.

Use the toString() method to convert the variable num to a string.

Similar Posts