Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm using let keyword in for loop gives SyntaxError: Unexpected identifier

I'm using let keyword in for loop as following

for(let methd1 in servUrl){
    let methd=methd1;
    for(let pth1 in servUrl[methd]) {
        let pth=pth1;
        app[methd](pth, servUrl[methd][pth]);
    }
}

which gives me following error

for(let methd1 in servUrl){
        ^^^^^^
SyntaxError: Unexpected identifier
like image 220
Akhilesh Kumar Avatar asked Oct 22 '15 03:10

Akhilesh Kumar


People also ask

How do I fix SyntaxError unexpected identifier?

To solve the "Uncaught SyntaxError: Unexpected identifier" error, make sure you don't have any misspelled keywords, e.g. Let or Function instead of let and function , and correct any typos related to a missing or an extra comma, colon, parenthesis, quote or bracket.

What does SyntaxError unexpected identifier mean?

"Unexpected identifier" means that you have a variable you're trying to reference that hasn't been declared. Make sure you pass all the variables you're trying to use into your template. All reactions.

What causes uncaught SyntaxError unexpected token?

The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. This might be a simple typo.


1 Answers

Can you please make sure, if you are using the supported version of node.

To know the node version you may run the following command:

$ node --version
v4.2.1

Node older versions do not support the let syntax or EcmaScript6 all features.

I also had experienced the similar issue and upgrading my node to latest solved my issue.

To upgrade node you can run the followings:

$ sudo npm cache clean -f
$ sudo npm install -g n
$ sudo n stable
like image 106
dopeddude Avatar answered Oct 12 '22 22:10

dopeddude