How to evaluate "1"+2+3+4+5=? in JavaScript?

 Posted by Vishalneeraj-24503 on 5/16/2015 | Category: JavaScript Interview questions | Views: 241 | Points: 40
Answer:

Consider the following Javascript code:-
<script language="javascript" type="text/javascript">

function Evaluate()
{
var i = "1";
var j = 2;
var k = 3;
var l = 4;
var m = 5;
alert(i + j + k + l + m);
}
</script>
<input type="button" id="calc" value="Click" onclick="Javascript:Evaluate();" />


Output:-
12345


Because "i" is string so all the variables considered as a string.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response