“JavaScript Object Destructing” Kode Jawaban

JavaScript Object Destructing

const employee = {name: ‘ANE01’, email: ‘[email protected]’, phone:’0112–345–6789'};
//with destucturing
const {name, email, phone} = employee;
//without destucturing
const name = employee.name;
const email = employee.email;
const phone = employee.phone;
Cute Civet

Cara Menggunakan Objek Menghancurkan

// Noob [ not good ]
function getFullName(userObj) {
  const firstName = userObj.firstName;
  const lastName = userObj.lastName;

  return `${firstName} ${lastName}`;
}

// master [ yap little bit ]
function getFullName(userObj) {
  const { firstName, lastName } = userObj;
  return `${firstName} ${lastName}`;
}

// hacker [ i prefer this way ]
function getFullName({ firstName, lastName }) {
  return `${firstName} ${lastName}`;
}
// example func call
getFullName({
	firstName: 'John',
    lastName: 'Duo'
});
Easy Earthworm

Jawaban yang mirip dengan “JavaScript Object Destructing”

Pertanyaan yang mirip dengan “JavaScript Object Destructing”

Lebih banyak jawaban terkait untuk “JavaScript Object Destructing” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya