I have declared const variable like,
"student.js"
export default const mark= 20;
I am Calling this constant in index.js file
"index.js"
import {mark} from './student';
console.log("Mark Value ::::" + mark);
am getting error????
export default expects an expression. While const is a statement.
You can't do export default const mark = 20 for the same reason you can't do console.log(const mark = 20).
If mark isn't used anywhere else in this file, it should be:
export default 20;
Otherwise it should be:
const mark = 20;
export default mark;
And imported like:
import mark from './student';
Adding to @estus answer, for your code to work change as follows.
"student.js"
export const mark = 20;
"index.js"
import {mark} from './student';
console.log("Mark Value ::::" + mark);
export defaultmeans you are exporting a module.export constmeans you are exporting part of a module and module will be formed later after combining all exports. So you should get error onexport default constitself