Forum Discussion

nish_b's avatar
nish_b
Contributor
6 years ago
Solved

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 Test {

var abc; //received above error

var abc = "Test"; //received above error

let def; //received above error

function1() {

//some code here

var abcd = "New"; //works fine here

}

 

Please suggest how I can create variables outside the functions in this scenario. Thanks!

 

  • Hi,

     

    I would like to see the source where your co-worker got this information.

    I do not remember to see any warning like this in the documentation and .CheckProperty() is the method that I use very often in my test code.

     

2 Replies