please delete me
please delete me

Reputation: 809

Why am I getting an "object expected" error in IE8?

This code:

function foo(){
    var x = 5;
    var y = "8.8";
    var exp1 = typeof(2 * y);
    var exp2 = typeof(x + y);
    var exp3 = typeof(parsefloat(x + y));
    var exp4 = typeof(x + parsefloat(y));
    var exp5 = typeof(x + parseint(y));
    var exp6 = typeof(x-y);
    var exp7 = typeof(x*y);
    alert( exp1 + ", " + exp2 + ", " + exp3 + ", " + exp4 + ", " + exp5 + ", " + exp6 + ", " + exp7 + "." );
}

Gives me an "object expected" error on the line starting with var exp3, character 2.

Edit:

Not necessary, but why is it an error on character 2?

Upvotes: 1

Views: 1440

Answers (4)

Bhesh Gurung
Bhesh Gurung

Reputation: 51030

parsefloat(x + y)

should be

parseFloat(x + y) // capital F

and

parseint(y)

should be

parseInt(y) // capital I

Upvotes: 2

Sahil Muthoo
Sahil Muthoo

Reputation: 12506

Change parsefloat and parseint to parseFloat and parseInt respectively.

Upvotes: 1

Rob W
Rob W

Reputation: 349252

JavaScript is case-sensitive. Use parseFloat and parseInt.

Upvotes: 5

Pointy
Pointy

Reputation: 414006

It's "parseFloat" and "parseInt". JavaScript is case-sensitive.

Upvotes: 1

Related Questions