OneBite.Dev - Coding blog in a bite size

convert variable from string to int in Javascript

Code snippet on how to convert variable from string to int in Javascript

  var myString = "10";
  var myInt = parseInt(myString);

This code shows how to convert a variable of type string to an integer in JavaScript. It begins by creating a string variable, myString, and assigning it an integer value that is represented as a string. Next, a new integer variable is declared and assigned a value by calling the parseInt() method. This method takes an argument of the string and returns an integer representation of it. Thus, the myInt variable will hold the integer representation of the myString variable, which is 10.

javascript