views:

67

answers:

1

This is javascript

var result = "2" + 5 + 5;

what would the value of result be? im guessing the 2 isnt taken into consideration?

would it be 210?

Thanks

+1  A: 

Just try it out. Include this code in a html page and run it.

    function test() {
      var result = "2" + 5 + 5;
      alert(result);
    }

The result is 255

And call the function somewhere:

<body onLoad="test();">
Prine
To nit-pick a bit: only if function `test` is called; simply adding that code to an arbitrary page will not alert `255`.
Marcel Korpel
@Marcel Okay, I added the function call as well ;)
Prine