Javascript destructing in Chrome console












0















I am trying JavaScript destructing with following code in Chrome's console tab which give me Uncaught SyntaxError: Identifier 'a' has already been declared exception



o = { a: "foo", b: 12, c: "bar" };
let { a, b } = o;
console.log(a);
console.log(b);

output:
foo
12


but just changing variable names, it runs fine, like following,



o = { p: "foo", q: 12, r: "bar" };
let { p, q } = o;
console.log(p);
console.log(q);


Can anyone explain me why is this happening ?










share|improve this question




















  • 1





    You already typed let a into your console or declared it somewhere on the page

    – Sebastian Speitel
    Nov 22 '18 at 18:35











  • maybe you have an old declaration of a ...?

    – Nina Scholz
    Nov 22 '18 at 18:35











  • I am trying it in new tab and haven't used anywhere else. Just writing above line in console.

    – Jaydeep Karena
    Nov 22 '18 at 18:36
















0















I am trying JavaScript destructing with following code in Chrome's console tab which give me Uncaught SyntaxError: Identifier 'a' has already been declared exception



o = { a: "foo", b: 12, c: "bar" };
let { a, b } = o;
console.log(a);
console.log(b);

output:
foo
12


but just changing variable names, it runs fine, like following,



o = { p: "foo", q: 12, r: "bar" };
let { p, q } = o;
console.log(p);
console.log(q);


Can anyone explain me why is this happening ?










share|improve this question




















  • 1





    You already typed let a into your console or declared it somewhere on the page

    – Sebastian Speitel
    Nov 22 '18 at 18:35











  • maybe you have an old declaration of a ...?

    – Nina Scholz
    Nov 22 '18 at 18:35











  • I am trying it in new tab and haven't used anywhere else. Just writing above line in console.

    – Jaydeep Karena
    Nov 22 '18 at 18:36














0












0








0








I am trying JavaScript destructing with following code in Chrome's console tab which give me Uncaught SyntaxError: Identifier 'a' has already been declared exception



o = { a: "foo", b: 12, c: "bar" };
let { a, b } = o;
console.log(a);
console.log(b);

output:
foo
12


but just changing variable names, it runs fine, like following,



o = { p: "foo", q: 12, r: "bar" };
let { p, q } = o;
console.log(p);
console.log(q);


Can anyone explain me why is this happening ?










share|improve this question
















I am trying JavaScript destructing with following code in Chrome's console tab which give me Uncaught SyntaxError: Identifier 'a' has already been declared exception



o = { a: "foo", b: 12, c: "bar" };
let { a, b } = o;
console.log(a);
console.log(b);

output:
foo
12


but just changing variable names, it runs fine, like following,



o = { p: "foo", q: 12, r: "bar" };
let { p, q } = o;
console.log(p);
console.log(q);


Can anyone explain me why is this happening ?







javascript destructuring google-chrome-console






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 18:35







Jaydeep Karena

















asked Nov 22 '18 at 18:33









Jaydeep KarenaJaydeep Karena

87311




87311








  • 1





    You already typed let a into your console or declared it somewhere on the page

    – Sebastian Speitel
    Nov 22 '18 at 18:35











  • maybe you have an old declaration of a ...?

    – Nina Scholz
    Nov 22 '18 at 18:35











  • I am trying it in new tab and haven't used anywhere else. Just writing above line in console.

    – Jaydeep Karena
    Nov 22 '18 at 18:36














  • 1





    You already typed let a into your console or declared it somewhere on the page

    – Sebastian Speitel
    Nov 22 '18 at 18:35











  • maybe you have an old declaration of a ...?

    – Nina Scholz
    Nov 22 '18 at 18:35











  • I am trying it in new tab and haven't used anywhere else. Just writing above line in console.

    – Jaydeep Karena
    Nov 22 '18 at 18:36








1




1





You already typed let a into your console or declared it somewhere on the page

– Sebastian Speitel
Nov 22 '18 at 18:35





You already typed let a into your console or declared it somewhere on the page

– Sebastian Speitel
Nov 22 '18 at 18:35













maybe you have an old declaration of a ...?

– Nina Scholz
Nov 22 '18 at 18:35





maybe you have an old declaration of a ...?

– Nina Scholz
Nov 22 '18 at 18:35













I am trying it in new tab and haven't used anywhere else. Just writing above line in console.

– Jaydeep Karena
Nov 22 '18 at 18:36





I am trying it in new tab and haven't used anywhere else. Just writing above line in console.

– Jaydeep Karena
Nov 22 '18 at 18:36












1 Answer
1






active

oldest

votes


















2














Well, both work ok the first time, the problem is you executed the code more than once. The next time you'll have that error because the var is already defined when you previously executed the code.



Try the following. Open a new chrome browser and type about:blank in the URL. type



let a;


in the console twice and you'll get the same error






share|improve this answer


























  • Hey friend, I am opening new tab and then opening console and pasted above code and it still gives error

    – Jaydeep Karena
    Nov 22 '18 at 18:41






  • 1





    @JaydeepKarena could be a global a in the page code already...try logging a by itself

    – charlietfl
    Nov 22 '18 at 18:42













  • While the code with variables p, q, r is working if I run them in another new tab console

    – Jaydeep Karena
    Nov 22 '18 at 18:42











  • maybe you're testing in a online environment, like @charlietfl said, try logging the var or build an empty html to isolate the test.

    – Pablo Ferro
    Nov 22 '18 at 18:44











  • wow, about:blank works for me! How is this possible

    – Jaydeep Karena
    Nov 22 '18 at 18:45











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436524%2fjavascript-destructing-in-chrome-console%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Well, both work ok the first time, the problem is you executed the code more than once. The next time you'll have that error because the var is already defined when you previously executed the code.



Try the following. Open a new chrome browser and type about:blank in the URL. type



let a;


in the console twice and you'll get the same error






share|improve this answer


























  • Hey friend, I am opening new tab and then opening console and pasted above code and it still gives error

    – Jaydeep Karena
    Nov 22 '18 at 18:41






  • 1





    @JaydeepKarena could be a global a in the page code already...try logging a by itself

    – charlietfl
    Nov 22 '18 at 18:42













  • While the code with variables p, q, r is working if I run them in another new tab console

    – Jaydeep Karena
    Nov 22 '18 at 18:42











  • maybe you're testing in a online environment, like @charlietfl said, try logging the var or build an empty html to isolate the test.

    – Pablo Ferro
    Nov 22 '18 at 18:44











  • wow, about:blank works for me! How is this possible

    – Jaydeep Karena
    Nov 22 '18 at 18:45
















2














Well, both work ok the first time, the problem is you executed the code more than once. The next time you'll have that error because the var is already defined when you previously executed the code.



Try the following. Open a new chrome browser and type about:blank in the URL. type



let a;


in the console twice and you'll get the same error






share|improve this answer


























  • Hey friend, I am opening new tab and then opening console and pasted above code and it still gives error

    – Jaydeep Karena
    Nov 22 '18 at 18:41






  • 1





    @JaydeepKarena could be a global a in the page code already...try logging a by itself

    – charlietfl
    Nov 22 '18 at 18:42













  • While the code with variables p, q, r is working if I run them in another new tab console

    – Jaydeep Karena
    Nov 22 '18 at 18:42











  • maybe you're testing in a online environment, like @charlietfl said, try logging the var or build an empty html to isolate the test.

    – Pablo Ferro
    Nov 22 '18 at 18:44











  • wow, about:blank works for me! How is this possible

    – Jaydeep Karena
    Nov 22 '18 at 18:45














2












2








2







Well, both work ok the first time, the problem is you executed the code more than once. The next time you'll have that error because the var is already defined when you previously executed the code.



Try the following. Open a new chrome browser and type about:blank in the URL. type



let a;


in the console twice and you'll get the same error






share|improve this answer















Well, both work ok the first time, the problem is you executed the code more than once. The next time you'll have that error because the var is already defined when you previously executed the code.



Try the following. Open a new chrome browser and type about:blank in the URL. type



let a;


in the console twice and you'll get the same error







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 18:42

























answered Nov 22 '18 at 18:39









Pablo FerroPablo Ferro

787




787













  • Hey friend, I am opening new tab and then opening console and pasted above code and it still gives error

    – Jaydeep Karena
    Nov 22 '18 at 18:41






  • 1





    @JaydeepKarena could be a global a in the page code already...try logging a by itself

    – charlietfl
    Nov 22 '18 at 18:42













  • While the code with variables p, q, r is working if I run them in another new tab console

    – Jaydeep Karena
    Nov 22 '18 at 18:42











  • maybe you're testing in a online environment, like @charlietfl said, try logging the var or build an empty html to isolate the test.

    – Pablo Ferro
    Nov 22 '18 at 18:44











  • wow, about:blank works for me! How is this possible

    – Jaydeep Karena
    Nov 22 '18 at 18:45



















  • Hey friend, I am opening new tab and then opening console and pasted above code and it still gives error

    – Jaydeep Karena
    Nov 22 '18 at 18:41






  • 1





    @JaydeepKarena could be a global a in the page code already...try logging a by itself

    – charlietfl
    Nov 22 '18 at 18:42













  • While the code with variables p, q, r is working if I run them in another new tab console

    – Jaydeep Karena
    Nov 22 '18 at 18:42











  • maybe you're testing in a online environment, like @charlietfl said, try logging the var or build an empty html to isolate the test.

    – Pablo Ferro
    Nov 22 '18 at 18:44











  • wow, about:blank works for me! How is this possible

    – Jaydeep Karena
    Nov 22 '18 at 18:45

















Hey friend, I am opening new tab and then opening console and pasted above code and it still gives error

– Jaydeep Karena
Nov 22 '18 at 18:41





Hey friend, I am opening new tab and then opening console and pasted above code and it still gives error

– Jaydeep Karena
Nov 22 '18 at 18:41




1




1





@JaydeepKarena could be a global a in the page code already...try logging a by itself

– charlietfl
Nov 22 '18 at 18:42







@JaydeepKarena could be a global a in the page code already...try logging a by itself

– charlietfl
Nov 22 '18 at 18:42















While the code with variables p, q, r is working if I run them in another new tab console

– Jaydeep Karena
Nov 22 '18 at 18:42





While the code with variables p, q, r is working if I run them in another new tab console

– Jaydeep Karena
Nov 22 '18 at 18:42













maybe you're testing in a online environment, like @charlietfl said, try logging the var or build an empty html to isolate the test.

– Pablo Ferro
Nov 22 '18 at 18:44





maybe you're testing in a online environment, like @charlietfl said, try logging the var or build an empty html to isolate the test.

– Pablo Ferro
Nov 22 '18 at 18:44













wow, about:blank works for me! How is this possible

– Jaydeep Karena
Nov 22 '18 at 18:45





wow, about:blank works for me! How is this possible

– Jaydeep Karena
Nov 22 '18 at 18:45


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436524%2fjavascript-destructing-in-chrome-console%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Futebolista

Feedback on college project

Albești (Vaslui)