score:6

Accepted answer

[es6 feature] first of all default keyword with export allows us to set anonymous name we want to set when we import it.

if you export it with

export const clock,

then you have to import it strictly(es6 way - using object destructuring syntax for named exports) with

import { clock } from './clock

or also can use import * as clocks from './clock' if you want to import all constants/variables(i.e. all named exports jammed into one object). this will make clocks as an object with all exported variables/anything within it.

like clocks = { clock : clock \\ import {clock} from './clock', .... }

named exports are useful to export several values. during the import, it is mandatory to use the same name of the module as it was defined in source file.

but a default export can be imported with any name for example:

export default k = 12; // in file test.js

import m from './test' // note that we got the freedom to use import m instead of import k, because k was default export

console.log(m);        // will log 12

score:0

its es6 feature, its just like giving an alias name or assigning one variable reference to another with some other name

behind the curtain it is like this when you import with some other name:

clock_1 = clock

score:1

because you use export default. which means that you export only that class so the name is not that relevant. anyway, that's why tslint(a set of rules) says that it's forbidden to use export default.


Related Query

More Query from same tag