0

In JS an "undefined" value could occur automatically by mistake.(eg:- if you call a function which does not return any thing)

Can a "null" value occur automatically?

2
  • 3
    Undefined does not occur because of a mistake, it is a designed feature. null cannot occur automatically (whatever automatically. means). You may be given null as a return value from an API, but it is neither automatic nor accidental. Commented Nov 2, 2020 at 20:41
  • 1
    Calling a function that doesn't exist throws a ReferenceError Commented Nov 2, 2020 at 20:41

1 Answer 1

2

undefined is what is returned when you attempt to access a property that is not there or an array value that is not there. It is also the initial value of a variable that has been declared, but not assigned a value yet. These are not really mistakes, but the way the language is designed when you request a value that is not there.

null does not occur by default like undefined does. If a variable or property or return value is null, that is because some programmer or API specifically assigned or returned null.

Also, calling a function that does not exist throws a ReferenceError.

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

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.