Tech Junkie Blog - Real World Tutorials, Happy Coding!: JavaScript : The eval() Function

Friday, November 5, 2021

JavaScript : The eval() Function

The eval() function in JavaScript provides the power of dynamic evaluation, it evaluates a strings of JavaScript codes and returns a value.  If you use the eval on pair of string numbers it will be forgiving and give you the number if it can.  For example if you type int

eval("4+5")  the result will be 9 even though it's a string







Just because you can evaluate numbers that are strings, are you supposed to do it?  It's something you have to consider carefully before you go down that path.

The eval() function takes a one argument a string.  It tries to parse the argument as JavaScript code, if it fails a SyntaxError is thrown.  If it is successful then a value is returned or an undefined is returned if there are no value.  Since eval() uses a lot of interpretation of the code performance can take a hit.

For example if you type in the following code you will get an undefined and a SyntaxError

console.log(eval(myvar));

var myvar = "my variable";


console.log(eval(myvar));











2 comments:






  1. error404-store




    - -- Spamming tools --




    1-- cpanel https ssl secure
    2-- shell ssl secure
    3-- web-mail
    4-- smtp
    5-- rdp with send bluster
    6-- scam pages
    7-- ceo or cfo leads




    -- Spy virus slinet Exploits --




    1-- privet rat
    2-- crypter exploits
    3-- privet rdp hosting
    4-- os andriod spy virus
    5-- iso iPhone spy virus
    6-- Nokia spy virus




    - -- scanners brute-force ---




    1-- linux roots
    2-- cpanel scanner
    3-- cpanel bruter
    4-- shell scanner
    5-- smtp scanner
    6-- smtp bruter
    7-- zimbra scanners


    - -------------------


    cpanel,shell,smtp,scampages,sender,ceo or cfo leads,rdp,spyvirus,crypter,exploits,scanners


    Telegram:- @Donsmith000


    icq :- @Donsmith000


    https://error404-store.blogspot.com



    ReplyDelete

Search This Blog