parseInt

parseInt – Parses a string as an integer

Description

parseInt(string string, integer radix)

Parameters

Name Description Type Default Optional
string string No
radix A numeric value between 2 and 36 specifying the representation. integer 10 No

Return values

Returns an integer representation of the string.

Examples

Example #1 – parseInt example
console.log(parseInt('123 String')); // 123 console.log(parseInt('String 123')); // NaN console.log(parseInt('12')); // 12 console.log(parseInt(12)); // 12 console.log(parseInt('12.42')); // 12 console.log(parseInt(Infinity)); // NaN console.log(parseInt('Infinity')); // NaN console.log(parseInt('255', 8)); // 173

See also

External references