Javascript destructing in Chrome console
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
add a comment |
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
1
You already typedlet ainto your console or declared it somewhere on the page
– Sebastian Speitel
Nov 22 '18 at 18:35
maybe you have an old declaration ofa...?
– 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
add a comment |
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
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
javascript destructuring google-chrome-console
edited Nov 22 '18 at 18:35
Jaydeep Karena
asked Nov 22 '18 at 18:33
Jaydeep KarenaJaydeep Karena
87311
87311
1
You already typedlet ainto your console or declared it somewhere on the page
– Sebastian Speitel
Nov 22 '18 at 18:35
maybe you have an old declaration ofa...?
– 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
add a comment |
1
You already typedlet ainto your console or declared it somewhere on the page
– Sebastian Speitel
Nov 22 '18 at 18:35
maybe you have an old declaration ofa...?
– 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
add a comment |
1 Answer
1
active
oldest
votes
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
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 globalain the page code already...try loggingaby itself
– charlietfl
Nov 22 '18 at 18:42
While the code with variablesp, q, ris 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:blankworks for me! How is this possible
– Jaydeep Karena
Nov 22 '18 at 18:45
|
show 4 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 globalain the page code already...try loggingaby itself
– charlietfl
Nov 22 '18 at 18:42
While the code with variablesp, q, ris 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:blankworks for me! How is this possible
– Jaydeep Karena
Nov 22 '18 at 18:45
|
show 4 more comments
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
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 globalain the page code already...try loggingaby itself
– charlietfl
Nov 22 '18 at 18:42
While the code with variablesp, q, ris 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:blankworks for me! How is this possible
– Jaydeep Karena
Nov 22 '18 at 18:45
|
show 4 more comments
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
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
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 globalain the page code already...try loggingaby itself
– charlietfl
Nov 22 '18 at 18:42
While the code with variablesp, q, ris 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:blankworks for me! How is this possible
– Jaydeep Karena
Nov 22 '18 at 18:45
|
show 4 more comments
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 globalain the page code already...try loggingaby itself
– charlietfl
Nov 22 '18 at 18:42
While the code with variablesp, q, ris 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:blankworks 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
|
show 4 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
You already typed
let ainto 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