mercredi 4 novembre 2015

Weird issue assigning to Var in Javascript Nodejs inside if-else

Variables cannot be assigned inside an if-else block.

Here is the code

            jobObject.rrrrrrr = 'rrrrrrrrr';

            if (jobObject.startTime) {
              if (jobObject.pauseStartTime < jobObject.startTime) {

                var eeeeeee = 'eeeee';

                jobObject.eeeeeeeeee = eeeeeee;


              } else {
                jobObject.duration = jobObject.pauseStartTime - jobObject.startTime;
                jobObject.timerStatus = TIMER_STATE.Pause;
              }
            }

Now, jobObject.rrrrrrr is assigned normally. But the jobObject.eeeeeeeeee is always undefined. Rather I am getting var eeeeeee itself to be undefined even though I have immediately assigned a string to it.

Please let me know what is the issue in this code. Though similar code seems to work normally in other places.

Aucun commentaire:

Enregistrer un commentaire