Would you please tell me why here used the 'null' as parameter in the function call? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Would you please tell me why here used the 'null' as parameter in the function call?

function myFunction(w, x, y, z) { console.log(w + x + y + z); } var args = [1, 2, 3]; myFunction.apply(null, args.concat(4));

21st Jan 2023, 8:36 AM
Sony
Sony - avatar
2 Answers
+ 7
Sony Hossain null is a primitive value it is used for missing object. To represent intentionally missing object null is used.
21st Jan 2023, 9:02 AM
RšŸ’ šŸ‡®šŸ‡³
RšŸ’ šŸ‡®šŸ‡³ - avatar
+ 3
You can pass a "context" to the apply method, this is the first argument, and referring to the context with the "this" keyword, the function itself can use values and variables that are defined elsewhere. null means that you are not giving any special context to this function. https://stackoverflow.com/questions/33640079/why-would-you-pass-null-to-apply-or-call
21st Jan 2023, 10:01 AM
Tibor Santa
Tibor Santa - avatar