The question is published on by Tutorial Guruji team.
I have the following code in a
let v = 1 console.log(v)
I open a CMD window in windows 10, run it and get an error that a semicolon is expected. What can I change (without babel) so that this code is run OK?
Remark: I understand this is supposed to be supported in ES6, and that in actuality it was even supported before but… now comes some explanation that I don’t really understand: until ES6 came along and then something (that I don’t understand either) happened.
My path is:
PATH=C:ProgramDataOracleJavajavapath; C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem; C:WINDOWSSystem32WindowsPowerShellv1.0; C:Program Files C:UsersuserAppDataLocalAndroidSdktools; C:Program Filesnodejs; C:Program FilesJavajdk1.8.0_172bin; C:Program FilesMicrosoft VSCodebin; C:UsersuserAppDataRoamingnpm; C:UsersuserAppDataLocalProgramsMicrosoft VSCodebin;
So maybe running in the cmd window is invoking nodeJS? I’m running 8.11.1
Your code is perfectly valid in ES6 (note: there’s no thing called ECMA6, it’s ECMAScript 6 or abbreviated as ES6).
A problem might be that if you run this script by entering its filename only (not
filename), that it is run by the Windows Script Host (
wscript.exe), which is the default way of running
.js files on Windows; however, it doesn’t support ES6.
To solve this issue, you have multiple ways:
- Always run scripts by prepending its filename by the name of the program, in this case,
- Change the default program associated with the file extension
.jsto Node.js (here‘s how to do it)