I would like to ask if it's possible to write an if-statement using a string and convert it somehow into a real statement?
I wish I could use "c==c"
like if(c==c)
.
Is that possible?
var c=1;
var aa= "c==c";
if(aa) {
console.log("abc")
}
I would like to ask if it's possible to write an if-statement using a string and convert it somehow into a real statement?
I wish I could use "c==c"
like if(c==c)
.
Is that possible?
var c=1;
var aa= "c==c";
if(aa) {
console.log("abc")
}
Yes, use Javascript's eval function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
Eval let's you run any string as valid Javascript code. However eval has a few downsides like performance and security since this can lead to vulnerabilities in your code if you let users eval any string they want.