shankar_r's avatar
shankar_r
Community Hero
8 years ago
Status:
New Idea

Identifying undefined variables in functions: JavaScript

I would like to request feature which will show a syntax error in Editor workspace for undefined variables as like in Eclipse.

 

In below example, Currently no syntax error is displayed but it is having warning or error which is undefined variable.

 

For Ex:

function test()
{
     var testvar = "1";
     
     if(testvar == expectedvar)
    {
         Log.Error("balhblah")
    }

}

Currently, we will come to know about undefined variables only when we run the function and also TC is taking around 15 + mins to identify this undefined variable. [I know this time is because i'm having huge units]

 

If we have this feature then it would be good suppress the undefined error.

 

2 Comments

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    That would be cool.  I'll upvote.

     

    Could be tricky, though... scripting languages are by their nature not very strict in variable declarations.  Technically speaking, in JavaScript, I don't need to use var blahblah to declare a variable... I can just start using a variable and JavaScript will just carry on as normal.

     

    I think DelphiScript is more strict as is VBScript... not sure about Python.  But JScript, C#Script, etc., in TestComplete are all based off a similar JavaScript engine so this might be a bit tough to implement.

  • shankar_r's avatar
    shankar_r
    Community Hero

    tristaanogre yes we can do scripting without declaring, However in below cases script fail due to undefined.

     

    1) Variable not declared but it is used in function parameter like below, In this case testvar is undefined hence it will shoot a error.

     

     

    function test()
    {
           var param1 = "test";
    
           testcalfunction(param1,testvar);
    }

    2) Variable declared but typo [this basically developer mistake but if have this option we can caught ]

     

    function test()
    {
           var para1 = "test";
           var testvar = "test2";
           testcalfunction(param1,testvar);
    }