Difference between Undeclared, Undefined and NULL in JavaScript

Views

Difference between Undeclared, Undefined and NULL in JavaScript

Undeclared

A variable used in the code which is not already declared with any keyword like var, let and const is called undeclared variable.

When we use it in the code gives an error.If we use typeof operator to get the value of it then return 'undefined' value.

 	console.log(r); // output as an error - Uncaught ReferenceError: r is not defined 
 	console.log(typeof d); // undefined 

Undefined

The undefined type has only one value, which is the special value undefined.

When a variable is declared using var or let but not initialized, It is assigned the value of undefined.

 	var a; 	
        let b; 	
        console.log(a); // undefined 	
        console.log(b); // undefined 

Null

The Null type is the second data type that has only one value: the special value null. Logically, a null value is an empty object pointer, which is why typeof returns “object” when it ’s passed a null value

 	var x = null; 	
        console.log(typeof x); //object 

How To Use Server-Sent Events …

How To Use Server-Sent Events in Node.js to Build a Realtime App. Server-Sent Events (SSE) is a technology based on HTTP. On the client-side, it provides an API called EventSource (part of the HTML5 standard) that allows us to connect to the server a …

read more
Views

How To Use node-cron to Run Sc …

How To Use node-cron to Run Scheduled Jobs in Node.js . cron provides a way to repeat a task at a specific time interval. There may be repetitive tasks such as logging and performing backups that need to occur on a daily or weekly basis.One method fo …

read more
Views