Skip to content Skip to sidebar Skip to footer

Calling A Javascript Function Without Arguments

Is it possible to call a javascript function without paranthesis? (). In the below code, from a book, has the line, http.onreadystatechange = useHttpResponse; If there is no para

Solution 1:

When assigning an event handler, you don't want to call the function, you're giving it a reference to a function, which will be called later.

So... no. () is used to mean "call this function", in this case with no arguments.

Solution 2:

It is the same way of :

functionadd2values(a, b) {
  return a + b
}

const objX = { name: 'xyz', myAdd: null }

objX.myAdd = add2values

console.log( objX.myAdd(1, 2) ) // -> 3

Post a Comment for "Calling A Javascript Function Without Arguments"