How to check if a variable is undefined or null in JavaScript?

Exactly, Priyanka! And if you’re working with modern JavaScript (especially with ES2020+ features), you can take advantage of optional chaining to make your code even more resilient. This is particularly handy when you’re dealing with deeply nested data structures, and you want to avoid any runtime errors when checking properties.

For instance:

if (EmpName?.length == null) {
  console.log("EmpName is missing or empty.");
}

With optional chaining, the ?. ensures that you don’t try to access .length if EmpName is null or undefined. This prevents errors without having to explicitly check for null or undefined. It’s a modern, cleaner approach to handle cases where a javascript check if null might pop up, especially in large, complex objects.