T
T
TosterUserName2018-03-22 22:05:39
JavaScript
TosterUserName, 2018-03-22 22:05:39

Will eval() work correctly?

I wrote the function myFunc, where, depending on the values ​​of the inputs, a condition is formed, written to a string and substituted into if through eval()to show the appropriate elements of the array (I'm sure this is more tricky, but I can only do this). I read that this is a eval()bad practice and should be avoided, but I did not understand anything. Can you please tell me if it will work correctly in my case?
https://codepen.io/mycodepenio/pen/xWrVVe

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Alexandrov, 2018-03-23
@TosterUserName

Will work. ;-) now it works.
But you can not follow the process of editing the code and the attacker will be able to execute arbitrary code on your site. This is why using eval() is considered a bad way.
Yes, and the logic is lost, it is difficult to understand what the code is doing.
And if you remember now, then, for example, in 5 years it will already be problematic to understand what and why.
Who prevents to store the results in another array, instead of forming a " tricky " string,
and then comparing it inside the loop of the original array. B-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question