-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjectEmpty.js
More file actions
26 lines (19 loc) · 796 Bytes
/
Copy pathobjectEmpty.js
File metadata and controls
26 lines (19 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* -------------------------------------------------------
* Programming Question : Check Object Emptiness
* -------------------------------------------------------
**/
// Q. Write a function isEmptyObject that takes an object as input and determines whether it is empty or not. An empty object is defined as an object with no own properties.
function isEmptyObject(obj) {
// for (let ob in obj) {
// if (obj.hasOwnProperty(ob)) {
// return "its not emtpy";
// }
// }
// return " empty";
return Object.keys(obj).length === 0 ? "Its empty" : "Its not empty"
}
console.log(isEmptyObject({ name: "vinod" }));
console.log(isEmptyObject({}));
console.log(isEmptyObject({ keyWithNull: null }));
console.log(isEmptyObject({ keyWithNull: undefined }));