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????
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????
Share Improve this question asked Feb 15, 2018 at 7:25 SuryaSurya 231 silver badge5 bronze badges 4- 2 am getting error???? You are asking or telling? – Rajesh Commented Feb 15, 2018 at 7:26
- import mark from './student'; – Surya Commented Feb 15, 2018 at 7:26
- it wont work . am asking the reason. – Surya Commented Feb 15, 2018 at 7:27
-
1
export default
means you are exporting a module.export const
means you are exporting part of a module and module will be formed later after bining all exports. So you should get error onexport default const
itself – Rajesh Commented Feb 15, 2018 at 7:29
3 Answers
Reset to default 9export 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);
What happens on export default var a = 10, b = 20, c = 30
?
Check out this discussion.