nish_b
6 years agoContributor
Variable declaration in a javascript class
Hi,
Can we declare global variables within a javascipt class, outside a function? When I try to declare a variable, it gives error: Syntax Error: Unexpected identifier
Sample code:
class Te...
- 6 years ago
This syntax is not allowed in ES6 JavaScript.
https://stackoverflow.com/questions/22528967/es6-class-variable-alternatives
https://stackoverflow.com/questions/41212099/making-a-es6-variable-global-in-a-class
This is not a TestComplete restriction but a restriction in the JavaScript language itself. To declare a variable within a class, it needs to be a property of the class or, as you did so, scoped within a method in the class. It's all about scoping and variables are not supported in the scope definition of a class.