About 189,000 results
Open links in new tab
  1. How can I convert a string to an integer in JavaScript?

    There are two main ways to convert a string to a number in JavaScript. One way is to parse it and the other way is to change its type to a Number. All of the tricks in the other answers (e.g., unary plus) …

  2. How can I check if a string is a valid number? - Stack Overflow

    To check if a variable (including a string) is a number, check if it is not a number: This works regardless of whether the variable content is a string or number.

  3. JavaScript string and number conversion - Stack Overflow

    Below is a very irritating example of how JavaScript can get you into trouble: If you just try to use parseInt() to convert to number and then add another number to the result it will concatenate two …

  4. Check whether variable is number or string in JavaScript

    Aug 20, 2009 · Does anyone know how can I check whether a variable is a number or a string in JavaScript?

  5. What's the best way to convert a number to a string in JavaScript ...

    None of the answers I see at the moment correctly convert -0 to "-0". Note that -0..toString() might appear to work, but it's working by converting 0 to "0", then applying the minus sign to it, actually …

  6. How does adding String with Integer work in JavaScript?

    Nov 29, 2016 · In JavaScript, the + operator is used for both numeric addition and string concatenation. When you "add" a number to a string the interpreter converts your number to a string and …

  7. javascript - Check if string contains only digits - Stack Overflow

    Here's another interesting, readable way to check if a string contains only digits. This method works by splitting the string into an array using the spread operator, and then uses the every() method to test …

  8. javascript - How to convert a string to number in TypeScript? - Stack ...

    Given a string representation of a number, how can I convert it to number type in TypeScript? var numberString: string = "1234"; var numberValue: number = /* what should I do with `numberString`? */;

  9. html - Javascript string/integer comparisons - Stack Overflow

    Mar 23, 2016 · Yes it gets a boolean from the < result and coerces it to string, but by then it's too late to affect how the comparison worked. JS < operator behavior depends on its two arguments: if both are …

  10. Javascript: Converting String to Number? - Stack Overflow

    The unary + operator: value = +value will coerce the string to a number using the JavaScript engine's standard rules for that. The number can have a fractional portion (e.g., +"1.50" is 1.5). Any non-digits …