Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Void function return value is used JavaScript [duplicate]

let btn = document.createElement("button");
btn.id = "submitBV"
let firstRow = 12
let lastRow = 59
btn.addEventListener("click", autoInput(firstRow, lastRow))

function autoInput(firstRow, lastRow){
    print()
}

It tells me Void function return value is used (screenshot).

After I add a return 1, it doesn't solve as well (screenshot2).

like image 323
Cookie Avatar asked Jul 27 '26 06:07

Cookie


1 Answers

Yes, because you are invoking the autoInput function which does not return something (void) valid. To handle this, to need to pass a function in order to be called when the click event is triggered by the button. In this case, you can add a simple function to do this.

btn.addEventListener("click", function() { autoInput(firstRow, lastRow); })

If you have a function which returns another function (if you are new to javascript, yes, it is possible) it may work fine, which is not your case on the autoInput function.

like image 95
Felipe Oriani Avatar answered Jul 28 '26 19:07

Felipe Oriani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!