there is a function:
function buildUser(first, last) { let fullName = first + " " + last; return {first, last, fullName}; } I create variables with it:
let {first, last, fullName} = buildUser("User1", "LastName"); console.log(first); console.log(last); console.log(fullName); everything works, but why I can’t create one more variables I don’t understand. I do this:
let {first, last, fullName} = buildUser("test1", "test1"); console.log(first); console.log(last); console.log(fullName); I get a syntax error:
SyntaxError: redeclaration of let first let {first, last, fullName} = buildUser("test1", "test1"); if I do with new variables, they turn out to be undefined:
let {first2, last2, fullName2} = buildUser("test1", "test1"); console.log(first2); console.log(last2); console.log(fullName2); what am I missing, please explain?
completely confused: such code for some reason does not work either:
function buildUser2 (first, last, postCount) { let fullNameMy = first + " " + last; const ACTIVE_POST_COUNT = 10; return { firstMy, lastMy, fullNameMy, isActive(){ return postCount >= ACTIVE_POST_COUNT; } } } let {firstMy, lastMy, fullNameMy} = buildUser2("test2", "test2"); console.log(firstMy); console.log(lastMy); console.log(fullNameMy); mistake:
ReferenceError: can't access lexical declaration `firstMy' before initialization
firstMythat is not declared in the method - Vasily Barbashev