1

I was following a tutorial online and they set the predefined value of the function as null(data and details), what is the use of the null, what does it mean

onClick={(data, details = null) => {
        console.log(data.description, details);
      }}
2

2 Answers 2

2

I think you know what is the notation of putting null in parameters and Set a default parameter value for a JavaScript function explains it further.

There are usages of putting default value to null.

  1. You can easily check whether values are assigned with lesser code. ex: if(details){}
  2. You can directly send that to database as a null value.
  3. You may do not prefer default undefined value based on your application requirements

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

1

null is a false-evaluated ("falsey") JavaScript object type whereas an empty object (like one defined via {}) is a true-evaluated ("truthy") object.

In many situations I have seen, developers will use it to signify the parameter is expecting an object because typeof null === "object". Without the details = null, a missing details parameter would be undefined, a type all of its own (typeof undefined === "undefined").

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.