Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight Undefined Javascript Variables in Visual Studio Code

One of my faviourite mistakes in Javascript is to forget to define variables I am using locally in a function. As you all know, due to scope, this is not always an error.

Is there any way in Visual Studio Code to highlight variables that are not defined in the function?

For example, say I have the function:

function MyFunction(argument1){ /* Note: not argument5 */
    var i; /* Note: not j */
    var arr1 = []; /* Note: not arr2 */

    ... /*Exciting code in between */

    len = 7;

    for(j=0;j<len;j++){
        arr2[j] = "Wibble" + argument5;
    }
}

I want len, j, arr2 and argument5 all to be highlighted in some way to show they are not defined locally in the function.

like image 632
Rewind Avatar asked Aug 30 '25 15:08

Rewind


1 Answers

Enable JS/TS › Implicit Project Config: Check JS in vscode settings.

Screenshot

like image 113
farhan ali Avatar answered Sep 02 '25 17:09

farhan ali