How can I use the setTimeout() statement? [duplicate] - javascript

This question already has answers here:
Why is the method executed immediately when I use setTimeout?
(8 answers)
How can I pass a parameter to a setTimeout() callback?
(29 answers)
What is the difference between a function call and function reference?
(6 answers)
Closed 3 months ago.
I was Coding Today (new) and i was wondering how people made js and python so i tried making a function based programming language using js
function init(){
log(console,"lmao ok")
setTimeout(log(console,'#--- Done'), 5000 )
}
function log(arg1,arg2) {
// body...
if (arg1 == console){
console.log(arg2)
}
else {
return
}
}
function prompt(arg1,arg2,arg3){
console.debug
var arg1 = "lmao"
}
init()
log(console,'tosay')

Related

repeat function with parameter by settimeout inside itselft [duplicate]

This question already has answers here:
Why can I not pass a function call (rather than a function reference or an anonymous function) to setTimeout()?
(5 answers)
How to access the correct `this` inside a callback
(13 answers)
Closed 2 years ago.
I need to iterate a function with its argument but got the recursion error
Error in mounted hook: "InternalError: too much recursion"
the function:
methods: {
showSlides: function(n) {
console.log(n);
setTimeout(this.showSlides(n), 3000);
//setTimeout(this.showSlides(n++), 3000);
}
},

Does onclick = function put that function in a new scope? [duplicate]

This question already has answers here:
Why JavaScript function declaration (and expression)?
(5 answers)
Why use named function expressions?
(5 answers)
Closed 2 years ago.
Need your assistance. I have a function that was defined in onclick event and when i try to call it later there is an error that says function undefined.
author.onclick = function authorSlideInfo(event){
// do work
}
authorSlideInfo.then(() => {
// do work
}
Function returns a promise and i want to do something else after it ends. Is my function not in global scope? How to overcome this?

how double parantheses ()() workes in JavaScript? [duplicate]

This question already has answers here:
Two sets of parentheses after function call
(4 answers)
Closed 4 years ago.
Here i have a question regarding Double parentheses, can anyone please explain me how does it works.
function counter() {
console.log("hI");
return function (){
console.log("inside hI");
}
}
counter()();
In your example counter returns a function, so having parentheses after the call to counter calls the function that counter returns

Javascript shorthand which calls functions [duplicate]

This question already has answers here:
Using ternary operator in JavaScript to invoke two functions
(2 answers)
Closed 5 years ago.
I want a shorthand that runs a function if true and runs a separate function if false. Something like:
(condition)? function1:function2;
condition? function1():function2();
function a() {
return "a";
}
function b() {
return "b";
}
(1 == 2) ? alert(a()) : alert(b());

JS function call [duplicate]

This question already has answers here:
Variadic curried sum function
(19 answers)
Currying in javascript for function with n parameters
(5 answers)
Closed 5 years ago.
How do I write a function which can be called several times in a row with one parameter? Here is an example:
function sum(a) {
// what should here?
}
sum(1)(2) // should return 3
Return another function that when called sums the argument of the first and the second like this:
function sum(a) {
return b => a + b
}
console.log(sum(1)(2))

Categories

Resources