Uncaught SyntaxError: Unexpected identifier, My Script Looks Fine Though

Okay so I just started learning javascript, I am familiar with how coding works I am just new to actually learning a coding language. I have been experimenting with things that I learned in codeacademy lessons by playing with inspect… and i even tried playing around with the terminal which is being really weird. So I created a javascript file with the following:

let w = 5
w = w + 4
console.log(w);

and the file I have is a javascript file… so it ends in .js . When I try to do node file.js in terminal it gives me Uncaught SyntaxError: Unexpected identifier. I know the code is not wrong because when I simply paste the url into the terminal (the url Visual Code gives me for my file under debug console.) bash executes the command just fine. I even tried setting the directory as the folder the file is in but it is not working with node. and node file.js command is not working. So is there something I have to put in my script for it to pick it up that way? or what? i’m just so confused right now. I hope this makes sense. Feel free to ask for clarity if you do not understand.

Can we have a link to the lesson you are having the problem with?

Hello! When I run the code on my computer, it works normally; can you send a screenshot of it with the error message, please?

it’s not a particular lesson i am just applying the code i was taught in the intro to java course lesson 2 to a concept i already know

Hello. I think I might have found the problem… For some reason node file.js is not being recognized as a command anymore… i have to do .load file.js . I don’t know if that’s officially the issue or if node should still be able to recognize “node file.js” but here is what it looks like on the terminal.

this is the actual script if it makes a difference.
Screen Shot 2022-02-03 at 5.47.40 PM

Nothing seems amiss from the code; I’d imagine it’s just how you were compiling (eh, not the most accurate term, oh well). I’m not too familiar with running JS through the terminal.

yeah well at least .load works and is running the file through node … so as long as it works in some way i guess its ok. its just kind of odd. Perhaps node changed how some stuff works, i have a mac if that makes a difference.

1 Like