Object Methods: =============== 1) assign(): ============ ==> It is an Object method which we can to create the new Object by copying the data from another object. Syntax: Object.assign(target, source) // User Profile let userProfile = { name : "Ishika", mail : "ishika.jain@gmail.com", age : 30 } // Update with new information let updatedInfo = { mail : "jain.ishika@gmail.com", phone: "123-456-7890" } // new object with existing profile and updated informarion let updatedUserProfile = Object.assign({},userProfile,updatedInfo) console.log(userProfile); console.log(updatedUserProfile); ================================================= const defaultSettings = { theme : "dark", notifications : true, autoSave:true }; const userSettings = { theme : "light", autoSave:false }; const finalSettings = Object.assign({},defaultSettings,userSettings); console.log(finalSettings); ======================================================= 2) entries(): ============= ==> Object Method ==> return: an array of key-value pairs. // User profile show as report. const userProfile = { name : "Sachin", age : 30, mail : "sachin.josh@gmail.com", location : "Delhi" }; console.log("The User Profile is = "); console.log(userProfile); console.log("The User Profile as Report:"); Object.entries(userProfile).forEach(([key,value]) =>{ console.log(`${key.toUpperCase()} : ${value}`); }); console.log(Object.entries(userProfile)); ==================================================== fromEntries(): ============= ==> Object method ==> create an object from list of key-value pairs. // URL with Query Parameters ===> convert into Object const queryString = '?name = John&age = 30&country = USA'; const queryParams = queryString.substring(1).split('&').map(param => param.split('=')); console.log(queryString); console.log(queryParams); const queryObject = Object.fromEntries(queryParams); console.log(queryObject); ================================================== Setter and Getter method: ========================= ==> JavaScript is kind of an Object Oriented Programming Language. High-level Languages 1) Functional Programming Languages/Procedural Programming languages 2) Object Based Programming Languages 3) Object Oriented Programming Languages { line1; line2; line3; functions{ } } Object Oriented Programming System (OOPs) ========================================= Concepts: class, Object, methods, constructor principles: Encapsulation polymorphism inheritance abtsraction ==> to initialize the private data members of class, we can use "setters and getters" methods. setter ==> setter can set the value for private variable getter ==> used to get the value of private variable. Note: ==== In JavaScript, there are no keywords available to denote access modifiers. public data can be used without the prefixing of any symbol. private data name can be prefixed with '_' protected data name can be prefixed with '__'. class ==> a blueprint collection of data members and methods ==> logical entity. object ==> a physical entity a reference/instance for the class. // user profile class UserPofile{ constructor(firstName,lastName,age){ // a constructor can be invoke at the time of object creation for a class. this.firstName = firstName; this.lastName = lastName; this._age = age; // private data member // to differentiating the local variable and class variable, this keyword can be used with class variables. // here: firstName, lastName and age ==> local variables // where as this.firstName, this.lastName and this.age ==> class variables/Instance Variables. } // getter method for fullName get fullName(){ return `${this.firstName}${this.lastName}` } //setter method for full name set fullName(name){ const[first,last] = name.split(" "); this.firstName = first || ""; this.lastName = last || ""; } // fullName is the property was added newly into UserProfile class. //getter method for private member age (existing) get age(){ return this._age; } //setter method for private member age set age(value){ if(value > 0 && value < 120){ this._age = value; } else{ console.error("Invalid age! Age must be between 1 to 120."); } } } // creation of an object const user = new UserPofile("Ishika","Jain",26); console.log(user.fullName); console.log(user.age); // update on the UserProfile Class Property. user.fullName = "Jain Ishika"; console.log(user.fullName); user.age = 30; console.log(user.age); user.age = -10; console.log(user.age);