javascript / beginner
Snippet
Converting Strings to Integers with parseInt
In Node.js and browser JavaScript, parseInt() takes a string and converts it into a whole number (integer).
snippet.js
1
2
3
const numericString = "42";const result = parseInt(numericString);console.log(result + 8);
nodejs
Breakdown
1
const result = parseInt(numericString);
Parses the string "42" and returns the number 42.