Sitemap

Null vs undefined

May 7, 2025

--

console.log(“hello”);
output:
hello
undefined
// it returns undefined after hello, because console.log() is a function and its not returning anything, so the return value would be undefined.

Get Sirisha komma’s stories in your inbox

Join Medium for free to get updates from this writer.

in JavaScript, if a function doesn’t explicitly return anything, its return value is automatically undefined.

var str=”hello”;
str.match(“Hi”);
output: null
here match() function should always return something. this time “hello” does not match with “Hi” so it is returning null.

undefined vs null
undefined
= never got anything.
null = got something… and that something is nothing.

--

--