In javascript,I import a named object like this:
import {my_object} from './my_js.js'
Is some sort of destructuring happening in this above mentioned import statement or using curly braces is just a requirement for importing named object?
thanks in advance
Although the syntax looks very similar to destructuring, and the operation being performed is somewhat similar to destructuring (in that it takes the my_object
binding from the namespace and puts it into an identifier), it's something quite distinct. For a couple of examples...
With destructuring, you can destructure nested properties of an object. This is impossible to do (in one statement) with imports.
With destructuring, you can put the property into a different variable with a colon. With imports, as
must be used instead.
const { prop: propIdentifier } = obj;
import { theName as theNameIdentifier } from './somefile';
using curly braces is just a requirement for importing named object?
Exactly.
There are things you can do with destructuring that you can't do when importing, and there are things you can do when importing that you can't do with destructuring.