Ads by ProfitSence
Close

Javascript empty function Code Example

Last Updated on Wednesday 5th Oct 2022

Example 1: Check if Empty

			
					const isEmpty = value =>
        value === undefined ||
        value === null ||
        (typeof value === "object" && Object.keys(value).length === 0) ||
        (typeof value === "string" && value.trim().length === 0);

			
	
			
					console.log(isEmpty("")); // true
console.log(isEmpty(" ")); // true
console.log(isEmpty("sdff")); // false

			
	

Example 2: Empty JavaScript Function

			
					const func = () => {};

			
	

Example 3: Check if Object is empty

			
					function isEmptyObj(value) {
  return Object.keys(value).length === 0 && value.constructor === Object;
}

			
	
			
					console.log(isEmptyObj({})); // true