javascript - SyntaxError: Use of const in strict mode -


i'm working node.js, , in 1 of js files i'm using const in "strict mode". when trying run it, i'm getting error:

syntaxerror: use of const in strict mode. 

what best practice this?

edit:

'use strict' const max_image_size = 1024*1024; // 1 mb 

the const , let part of ecmascript 2015 (a.k.a. es6 , harmony), , not enabled default in node.js 0.10 or 0.12. since node.js 4.x, “all shipping [es2015] features, v8 considers stable, turned on default on node.js , not require kind of runtime flag.”. node.js docs has overview of es2015 features enabled default, , require runtime flag. upgrading node.js 4.x or newer error should disappear.

to enable of ecmascript 2015 features (including const , let) in node.js 0.10 , 0.12; start node program harmony flag, otherwise syntax error. example:

node --harmony app.js 

it depends on side strict js located. recommend using strict mode const declarations on server side , start server harmony flag. client side, should use babel or similar tool convert es2015 es5, since not client browsers support const declarations.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -