1) eval is used to evaluate the expression.
Example:
var iValue =10;
document.write(eval(iValue+10));
eval("iFirst=10;iSecond=20;document.write(iFirst*iSecond)");
Output:
20
200
2) eval used to reduce the number of lines.
Suppose you are doing some validation part.
Without eval
if (document.myForm.Name.value.length==0)
{
alert("Name requires a value");
}
if (document.myForm.Salary.value.length==0)
{
alert("Salary requires a value");
}
Using eval
var fieldList = new Array('Name','Salary');
var tempObj;
for (count=0;count<fieldList.length;count++)
{
tempObj=EVAL("document.myForm." + fieldList[i]);
if (tempObj.value.length==0)
{
alert(fieldList[i] + " requires a value");
}
}
3) eval can be used to generate dynamic variable.
eval("iValue" + iIndex);
Same way we can use window["iValue"+ iIndex]
Friday, April 15, 2011
Subscribe to:
Post Comments (Atom)
Followers
Link
Labels
Agille
(3)
Angular 2
(96)
Architecture
(7)
ASP .Net
(30)
C#/VB .Net
(161)
Entityframework
(11)
General
(33)
Git
(2)
Hosting
(2)
HTML
(4)
Interview
(12)
Interview-Agile
(1)
Interview-Angular
(25)
Interview-ASP .Net
(3)
Interview-C#
(16)
Interview-JavaScript
(1)
Interview-MVC
(30)
Interview-SQL Server
(4)
Interview-WCF
(2)
Islam
(6)
Java Script
(37)
JQuery
(1)
MVC
(53)
NodeJS
(1)
Puzzles
(1)
React-Native
(3)
Security
(1)
Shayri
(10)
SQL Server
(41)
VC++
(5)
WCF
(21)
Web API
(27)
WPF
(21)
1 comment:
I read your post about Java Serialization and its indeed useful man keep it up
Interview Questions
Post a Comment