Chocolate570 Posted October 9, 2005 Share Posted October 9, 2005 Well, i was making a calculator and was having trouble with the + operator because the input was from a text box, making it a string. I went to w3schools, and found the eval function. It worked. But i want to know, what happens if you throw letters at it? I tried using it for a thing that stops any letters in the text box at the top of the calculator...but it didn't work. I found out how to do that, but what does it do?Thanks in Advance.Choco Link to comment Share on other sites More sharing options...
Webworldx Posted October 9, 2005 Share Posted October 9, 2005 Think of it as if it didn't have eval around it at all - so if you've got:3 + 6 + youit's going to error, unless you have a variable called you. It's a useful thing for converting text to javascript statements, like: <script type='text/javascript'>var t = 8var i = eval("3+5+t");alert(i);</script> If you can understand that. Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 10, 2005 Author Share Posted October 10, 2005 What if inside the variable "t" was the letters "abc"? What would it give? An error? Link to comment Share on other sites More sharing options...
Webworldx Posted October 10, 2005 Share Posted October 10, 2005 Yup. Unless you had a variable called abc. Link to comment Share on other sites More sharing options...
aaronjones3593 Posted October 16, 2005 Share Posted October 16, 2005 Yup. Unless you had a variable called abc.<{POST_SNAPBACK}> eval() is a function to evaluate a piece of javascript code, like so:eval("alert('Hello')"); Notice two things:1: The code must be inside quotes ( "" )2: The code inside the quotes cannot end with a semi-colon ( ; ), which means you can only evaluate 1 line of code at a time.I had to use eval() when I made my own game... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now