Optional chaining '?.' thumbnail
Optional chaining '?.'
javascript.info
The optional chaining ?. stops the evaluation if the value before ?. is undefined or null and returns undefined. As it was said before, the ?. immediately stops (“short-circuits”) the evaluation if the left part doesn’t exist. So, if there are any further function calls or operations to the right o
7 Users
0 Comments
37 Highlights
0 Notes

Top Highlights

  • The optional chaining ?. stops the evaluation if the value before ?. is undefined or null and returns undefined.
  • As it was said before, the ?. immediately stops (“short-circuits”) the evaluation if the left part doesn’t exist. So, if there are any further function calls or operations to the right of ?., they won’t be made.
  • userAdmin.admin?.(); // I am admin userGuest.admin?.(); // nothing happens (no such method)
  • The optional chaining ?. has no use on the left side of an assignment.
  • let html = document.querySelector('.elem')?.innerHTML; // will be undefined, if there's no element

Ready to highlight and find good content?

Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.