Js: What happens when curly brackets enclose the variable declaration? [duplicate] - javascript

This question already has answers here:
What does this symbol mean in JavaScript?
(1 answer)
Javascript object bracket notation ({ Navigation } =) on left side of assign
(5 answers)
What is destructuring assignment and its uses?
(3 answers)
Closed 2 years ago.
I am trying to understand the following expression.
const {
TARGET = 'http://localhost:8080',
PORT = 80
} = process.env;
How does variable declaration enclosed by curly brackets work?
And how does the value assignment for process.env works?
Does this type of expression have a name?

Related

javascript - what does ${} do? [duplicate]

This question already has answers here:
What does ${} (dollar sign and curly braces) mean in a string in JavaScript?
(6 answers)
What does this symbol mean in JavaScript?
(1 answer)
Closed 2 years ago.
I have seen ${ } being used in many javascript codes. What exactly does this do?
For example:
updateDisplay(){
if(this.operation != null){
this.previousOperandTextElement.innerText = ${this.previousOperand} ${this.operation};
}
this.currentOperandTextElement.innerText = this.currentOperand;
}
Why would we not use + to concatenate in this case?
It's called a template literal. It achieves the same thing as concatenation but in a more readable manner:
const a = "Hello"
const b = "."
console.log(`${a} World${b}`)

Why does adding object literal + array literal result in 0 in JavaScript? [duplicate]

This question already has answers here:
What is the explanation for these bizarre JavaScript behaviours mentioned in the 'Wat' talk for CodeMash 2012?
(5 answers)
Objects and arrays addition
(4 answers)
Closed 3 years ago.
Why is the result of the expression {}+[] 0?
It appears that the + is treated as a unary operator instead of a normal addition operator. The expression then becomes {}0. Why is this valid JavaScript and why is the result 0? Why is the object literal in the expression ({})+[] treated normally?
Note: I tried searching for a similar question in SO but it doesn't look like searching using symbols works.

Why the parentheses around numbers are required to call Number methods [duplicate]

This question already has answers here:
Why can't I access a property of an integer with a single dot?
(5 answers)
Why does 10..toString() work, but 10.toString() does not? [duplicate]
(3 answers)
Why don't number literals have access to Number methods? [duplicate]
(3 answers)
Closed 3 years ago.
The following syntax generates an error:
5.toString();
But the following doesn't:
(5).toString();
What does the parentheses exactly do here?

Is there a special meaning for the () operator in javascript? [duplicate]

This question already has answers here:
Does the comma operator influence the execution context in Javascript?
(2 answers)
What's the reason for using such syntax (0, _.Em)();
(1 answer)
Closed 5 years ago.
I'm working with some javascript generators. It has generated a line like:
(0, _myTest.testfunc)();
What is the meaning of this line?
OK - The testfunc is the a function that should be called and comes from a module loader. But what is the meaning of the first () with the comma between?

space in object key javascript [duplicate]

This question already has answers here:
JavaScript property access: dot notation vs. brackets?
(17 answers)
Closed 8 years ago.
I didn't know that this is possible in JavaScript:
var test = {
"hello world": function(){
console.log('test');
}
};
Of course this is only a theoretical question:
Is there a possible way to call the hello world function other than test["hello world"]()?
Would it be possible to call it with the . operator?
Sorry but if key is has some special character then you cannot call this with '.' operator.
only way to call is bracket notation which you already know

Categories