That's only half-true. For example, JS itself will tell you it's true:
eval===window.eval// true
However, calling eval directly and calling window.evaldon't always give identical results. This is due to the special semantics of direct eval:
Although the expression eval(x) looks like a normal function call, it actually takes on special behavior in JavaScript. Using eval in this way means that the evaluated code stored in x can reference any variable in any containing scope by name. For example, the code let y = 123; return eval('y') will return 123.
Tech Lead/Team Lead. Senior WebDev. Intermediate Grade on Computer Systems- High Grade on Web Application Development- MBA (+Marketing+HHRR). Studied a bit of law, economics and design
Location
Spain
Education
Higher Level Education Certificate on Web Application Development
This is very true, even if you instantiate functions instead of eval, everything is a prototype with access to the Function constructor. Here is the most common occurrence I see.
<div> We found { count } hits for { search } </div>
eval is also a code smell. devs use it in frameworks and libraries to be clever, but there is no reason to use it. if you're making something to handle user input, you're better off writing a customer parser to handle your specific use case.
That's only half-true. For example, JS itself will tell you it's true:
However, calling
evaldirectly and callingwindow.evaldon't always give identical results. This is due to the special semantics of direct eval:Here's a more complete example:
you are right,professional enough.
Got to love how JavaScript can take forms which look more like cryptic magic spells than the actual code 🙃
JavaScript is cool,my favorite programming language.
So true 😂
you can prevent the accidential use of eval by overloading this function:
it's a good idea!
The lesson to learn here would be: anything could be an eval, cut and paste code carefully.
YES!
This is very true, even if you instantiate functions instead of eval, everything is a prototype with access to the Function constructor. Here is the most common occurrence I see.
then a user searches for something like this
eval is also a code smell. devs use it in frameworks and libraries to be clever, but there is no reason to use it. if you're making something to handle user input, you're better off writing a customer parser to handle your specific use case.
It is still not safe. You can use jspython interpreter (jspython.dev) for safe evaluation within JavaScript (browser or NodeJS)
Nice