Home > Code > Javascript > How do evaluate “1”+2+3+4+5=? in JavaScript?

How do evaluate “1”+2+3+4+5=? in JavaScript?

by Spidy   on May 15, 2011   Category: Javascript   |  Views: 4282    |  Points: 25   |  Silver 


Find the below JavaScript sample code and result as well

<!<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Javascript Questions</title>
<script language="javascript" type="text/javascript">
function JavaScriptWorks()
{
var i = "1";
var j = 2;
var k = 3;
var l = 4;
var m = 5;
alert(i + j + k + l + m);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="calc" value="Click" onclick="Javascript:JavaScriptWorks();" />
</div>
</form>
</body>
</html>

Output

12345

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



Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts