Search code examples
javascriptphotoshop-script

Duplicate variable creation in JavaScript - Is it problematic?


I've noticed Photoshop's ScriptListener code kick out a duplicate line.

    var idChnl = charIDToTypeID( "Chnl" );
    var idChnl = charIDToTypeID( "Chnl" );

This ScriptListener bug aside, my question is this: Is it problematic, when a variable in a script, (such as idChnl), is created twice?


Solution

  • The second variable assignment (or if more than two variable assignments, the last variable assignment) will overwrite the initial assignment(s) as seen in this example:

    var a = "Hello";
    var a = "World";
    
    alert(a);

    With regards to problems with this, code readability and confusion with code maintenance in the long run are a few of the problems I could think of.