Recently I've seen a JavaScript code type, in some examples of Electron, which I believe to be part of ES6. They are variable declarations in the following format:
const electron = require('electron');
// Module to control application life.
const {app} = electron;
// Module to create native browser window.
const {BrowserWindow} = electron;
Here it is being used with const
, but I do not know if this also exists with let
and var
.
The important thing here is that instead of declaring in the usual way
const app = electron;
const BrowserWindow = electron;
We're putting app
and BrowserWindow
in braces.
What does this kind of declaration mean with the name of the variable inside braces? When and how should this type of declaration be used?