About which error will display

I have the following code:

const entree='Enchiladas'
const testing;

which error will console display? In other words,

If you have a TypeError that generated by line 3 and a syntax error generated by line 4, what will console print?
this code comes from this exercise: https://www.codecademy.com/courses/introduction-to-javascript/lessons/variables/exercises/const

This error would show (file name and variable names are different):


entree = ‘Tacos’

TypeError: Assignment to constant variable.
at Object. (/home/ccuser/workspace/learn-javascript-variables-constV2/main.js:3:8)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3

Also, don’t forget to format your code correctly: [How to] Format code in posts

If code run from top to bottom, it should encounter the line three error first, why it should line 4 error first?

1 Like

I don’t understand what you are saying. But yes the code does run from line 1 to line x but if an error occur it will stop running the program

I mean third line of code will produce typeError because we can’t change the value for const. But the error display syntax error. Why the error of typeError didn’t get produce first?

1 Like

The Type error on line 3 would be printed and not the syntax error on line 4. Its because the compiler stops reading the code after the encounters the error on line 3 so it does not know about the error on line 4.