javascript eval() function
eval(new String('2 + 2')); // returns a String object containing "2 + 2"
eval('2 + 2'); // returns 4
javascript eval() function
eval(new String('2 + 2')); // returns a String object containing "2 + 2"
eval('2 + 2'); // returns 4
eval()
#Perfect if you want to store a mathematical expression without defining the
#variables used:
my_function = "5x**2 + 8x - 2" #I want to define the function cleanly as a
# variable
#insert definition of other varianles here
#insert other code here
def f(x): #Defining the function as the funtion f(x)
return eval(my_function) #Returning my_function with the x in f(x) as x
print(f(0)) #Printing f(0), thereby returning my_function with 0 as x
#Returns -2
eval javascript
eval(string)
The eval() function
console.log(eval('2 + 2'));
// expected output: 4
console.log(eval(new String('2 + 2')));
// expected output: 2 + 2
console.log(eval('2 + 2') === eval('4'));
// expected output: true
console.log(eval('2 + 2') === eval(new String('2 + 2')));
// expected output: false
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us