I have a text box where the user can enter javascript code, which after clicking the button will be passed to eval ().
I am having trouble intercepting a referenceError for cases where the user enters something like this:
var myName = Maria;
instead
var myName = "Maria";
Thank you for your time!
Well, as you said, you understood the pit eval(), here I offer a solution.
eval()
try { var myName = Maria; } catch (e) { if (e instanceof ReferenceError)) { // take necessary steps }
Try putting a try / catch block around the call to eval (). Like this:
try { eval(userInput); } catch (e) { // do something }
( , eval() -, .)
Source: https://habr.com/ru/post/1607063/More articles:Polymorphism and the virtual method - polymorphismAdd hook / callback when cursor moves when entering raw_input? - pythonTransfer application to SD card - androidJQuery: предотвращать события, определенные в AjaxComplete, для привязки (и срабатывания) несколько раз - javascriptHow to use getUpdates after setWebhook in Telegram Bot API - telegramHow to scroll two div elements at the same time - jqueryGetting values of all CSS properties of a selected element in Selenium - javaAsync.retry runs just before waiting for an interval - javascriptConfused about composite indexes and FFS - performanceDesign ++ operator to iterate over some animation elements - c ++All Articles