Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Override Variable

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #175838
    Anonymous
    Inactive

    I have a global variable thats this

    var myNumber = 50;

    I want to override the value of that variable only when an if statement is true.

    I tried this
    var myNumber = 50
    if ( 12 == 12 ) { var myNumber = 25; }

    #175839
    Anonymous
    Inactive

    Nevermind. I put the if statement before the variable served its purpose.

    #175844
    nixnerd
    Participant

    Here you go @Jarolin

    var myNumber = 50
    
    if (12 == 12){
      myNumber = 25;
    }
    
    #175845
    nixnerd
    Participant

    You don’t need to re-declare the variable. It already exists. You just need to re-assign value.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.