-1

Why do i get the error

TypeError: Cannot set properties of undefined (setting '6')
at Object.<anonymous> (/home/runner/*******/index.js:5:8)
at Module._compile (node:internal/modules/cjs/loader:1101:14)

in my code that I tried to swap varibles' content using the destructuring assignment i got that error and im shure that there is no misstaque and I'm not that great of a dev so please help me my code "formated":

let [a,b] = [8,6];
console.log("a:" ,a ,"b:", b)
[a, b] = [b, a]
console.log("a:" ,a ,"b:", b)

the result "try it your self please":

a: 8 b: 6
TypeError: Cannot set properties of undefined (setting '6')
    at Object.<anonymous> (/home/runner/seeing-what-is-js/index.js:5:8)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
jabaa
  • 3,902
  • 3
  • 6
  • 24
  • 2
    Use semicolons: `;`. JavaScript has automatic semicolon insertion (ASI), but I recommend avoiding it and manually set them. After adding the semicolons, the code works. – jabaa May 22 '22 at 17:10

1 Answers1

-1

Missing semicolon after console.log call

automatic semicolon insertion (JS) read it up for more informations.

Mexa
  • 1
  • 1
  • 2