JavaScript parseInt() Function

Example

Parse different strings:

var a = parseInt(“10”) + “<br>”;
var b = parseInt(“10.00”) + “<br>”;
var c = parseInt(“10.33”) + “<br>”;
var d = parseInt(“34 45 66”) + “<br>”;
var e = parseInt(” 60 “) + “<br>”;
var f = parseInt(“40 years”) + “<br>”;
var g = parseInt(“He was 40”) + “<br>”;

var h = parseInt(“10”,10)+ “<br>”;
var i = parseInt(“010”)+ “<br>”;
var j = parseInt(“10”,8)+ “<br>”;
var k = parseInt(“0x10”)+ “<br>”;
var l = parseInt(“10”,16)+ “<br>”;

var n = a + b + c + d + e + f + g + “<br>” + h + i + j + k +l;

The result of n will be:

10
10
10
34
60
40
NaN

10
10
8
16
16

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: