What is this Javascrip/node variable/constant assinging notation/syntax called ? [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)
Closed 4 years ago.
I've been trying to find out what this notation is called so I can better google it. It's from the gmail api node example but wont run for me.
const {client_secret, client_id, redirect_uris} = credentials.installed;
I think this is the correct stackexchange site for this, but if I'm wrong, happy to relocate it to a more appropriate one.

It is Destructuring Assignment

Related

What does the question mark (?) do when using it in response?.data | API | fetch API [duplicate]

This question already has answers here:
Question mark after parameter as in obj.val?.prop [duplicate]
(3 answers)
Question mark before dot in javascript / react [duplicate]
(1 answer)
Closed 2 months ago.
Do you know the expression ? when using it like this:
data?.name
I mean what does this question mark (?) in-between the data and the point do?
This is called "Optional chaining".
Say you make an axios request and expect the response.data object.
You don't KNOW if data will be there, but you expect it to.
The question mark is a shorthand for writing
data && data.name
If data is undefined, the data.name code does not run and thus you don't get an error (cannot access name of undefined)
it is called Optional chaining (?.), and basically it will return unidentified instead of throwing an error
you can read more about it here
https://developer.mozilla.org/enUS/docs/Web/JavaScript/Reference/Operators/Optional_chaining

In JavaScript what is this method called where you might define a variable or property as such variable_name$ref [duplicate]

This question already has answers here:
Rules for unquoted JavaScript Object Literal Keys?
(6 answers)
What characters are valid for JavaScript variable names?
(12 answers)
Closed 1 year ago.
I am seeing it crop up more and more in code I am going through on a new project (can't share due to contractual reasons) where Ill see something like:
{
prop1: value$ref,
$prop2: null
}
I have see ${prop3} before, but never an example without the brackets. Can anyone provide direction as to what the method is, or the operator is or whatever the case?

I want to know the const declaration type of js [duplicate]

This question already has answers here:
Javascript object bracket notation ({ Navigation } =) on left side of assign
(5 answers)
What is destructuring assignment and its uses?
(3 answers)
Closed 3 years ago.
I know how to declare const variable like const a = 1;
but I dont get what is this
const { app, BrowserWindow } = require('electron')
can anyone explain me?
That’s a destructuring assignment.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
It lets you make shortcuts to members of an array or structure.

Why use '{' and '}' to define a javascript variable [duplicate]

This question already has answers here:
Javascript object bracket notation ({ Navigation } =) on left side of assign
(5 answers)
What does this symbol mean in JavaScript?
(1 answer)
Closed 4 years ago.
I can't seem to find anything in the documentation to understand why the { and } characters are wrapped around variables on some examples I've seen. Can anyone example why we would do that?
For example:
const {app} = require('./app/app.js');

What does '=>' imply in typescript/javascript? [duplicate]

This question already has answers here:
What's the meaning of "=>" (an arrow formed from equals & greater than) in JavaScript?
(14 answers)
Closed 7 years ago.
So I have saw tons of '=>' in some code I found online. Can anyone explain to me like I'm 5?
(I am looking for code, and I will post it here once I find it)..
Got it:
var directive = () =>
{
return new MyDirective();
};
this is ECMASCRIPT 6 standard arrow function.
In this case directive is assigned a function with 0 arguments and one return statement
Details are documented here in MDN Docs
()=> is simply a lambda function, which (in this case) means nothing more than a shorthand notation for a function without a name taking 0 paramaters.
You could have written var directive=function(){return new MyDirective();};
Take a look at John Papas blog Post.

Categories

Resources