If I have this piece of code (which uses destructuring) seems it's creating new variables ss
and pp
.
But what is the scope of these? Are they created as var
or as let
variables?
Are they function or block scoped?
let config = {
server: 'localhost',
port: '8080',
timeout: 900,
};
/* no let or var here */ ({server : ss, port : pp} = config);
console.log(ss, pp);
They're global variables, just like in normal assignments. Your code is just shorthand for:
ss = config.server;
pp = config.port;
They are global. You can even prove this out through slight modification of your example. The console.log
statements both work in the following snippet. Both would fail if it was block-scoped, the first would pass but second would fail if it was function-scoped, but clearly both work.
(function() {
{
let config = {
server: 'localhost',
port: '8080',
timeout: 900,
};
({server : ss, port : pp} = config);
}
console.log(ss, pp);
})();
console.log(ss, pp);
I have a created a calculator using Jquery and Javascript, everything works fine in Chrome but not in Firefox. function validate(x, y, z) { if ((isNaN(x) || x == "") || (isNaN(y) || y == "")) { ...
I have a created a calculator using Jquery and Javascript, everything works fine in Chrome but not in Firefox. function validate(x, y, z) { if ((isNaN(x) || x == "") || (isNaN(y) || y == "")) { ...
With this HTML the function myFunc() can be executed. https://myurl.de/myjs.js has the function myFunc in it. <head> <script type="text/javascript" src="https://myurl.de/myjs.js"></...
With this HTML the function myFunc() can be executed. https://myurl.de/myjs.js has the function myFunc in it. <head> <script type="text/javascript" src="https://myurl.de/myjs.js"></...
I need to initialize a Vue component's data with the result of an AJAX call. I tried the following: data: function () { return { supplierCount: 0 } }, created: function () { axios.get("/...
I need to initialize a Vue component's data with the result of an AJAX call. I tried the following: data: function () { return { supplierCount: 0 } }, created: function () { axios.get("/...
I am stuck with ajax... I have a cart and it has gift vouchers, i) the code checks for valid voucher and if its not valid then it should show message "invalid voucher". ii) If voucher if valid and is ...
I am stuck with ajax... I have a cart and it has gift vouchers, i) the code checks for valid voucher and if its not valid then it should show message "invalid voucher". ii) If voucher if valid and is ...