01/07/2023
Alternative to Eval in JS
The Eval function is super useful but extremely dangerous to use here's a simple alternative to in.
When you think of a function you usually think of using it by its keyword like this:
function myFunction() {
// code
}
However this isn't the only way to use it, function is also its own function Function
to use it to evaluate code for you you can do something like this:
let code = `(test) => {
console.log(test);
}`;
let value = new Function("return "+code);
This will return a function that returns your function back. To use your function you will have to first call the new Function
and then use your function.
value()("Hello")
// "Hello"
Comments
Be the first to comment!
Read More
Making sticky elements in HTML and CSS.
Sticky elements are a useful feature in modern web design, as they allow certain elements on a webpage to remain visible even when the user scrolls. This can be useful for elements such as the n...

