-2
var sam = {
    name :"san",
    age:56,
    lastname:"tom"
}
 (({name,lastname})=>{
    console.log(name);
    console.log(lastname);
})(sam);

TypeError: {(intermediate value)(intermediate value)(intermediate value)} is not a function y it is showing error

  • You forgot the `;` after the object literal, so the parens after it are trying to call it as a function (with the IIFE being passed as an argument to it) – Quentin Apr 29 '20 at 12:59

1 Answers1

0

var sam = {
  name: "san",
  age: 56,
  lastname: "tom"
};

(person => {
  console.log(person.name);
  console.log(person.lastname);
})(sam);

Or with object destructure like in your example

var sam = {
  name: "san",
  age: 56,
  lastname: "tom"
};

(({name, lastname}) => {
  console.log(name);
  console.log(lastname);
})(sam);

Or whith the old function Syntax

var sam = {
  name: "san",
  age: 56,
  lastname: "tom"
};

(function(person) {
  console.log(person.name);
  console.log(person.lastname);
})(sam);
SaymoinSam
  • 2,649
  • 2
  • 3
  • 17