1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Do you declare empty variable null or false when prepare to receive data

Discussion in 'JavaScript' started by ketting00, May 1, 2015.

  1. #1
    Hi guys,

    It seems stupid question but I'm seeking the best practice so it won't get me headache in the future.

    I need to declare an empty variable. Its value would then set as stream data (some times during the day) at a rate around 8k bytes every 16ms. So what is the best practice between these options:
    
    var streamDataValue;
    var streamDataValue = null;
    var streamDataValue = false;
    
    Code (markup):
    At the end of the day I would stop receiving the stream with:
    
    streamDataValue.stop(); // release the stream to receive new one
    
    Code (markup):
    Hope you get the picture.
    Thank you,

    Edit: Data is string not array.
     
    ketting00, May 1, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Why don't you declare it on demand - ie, when you need it? Do you have to have the variable set to false or null or just exist before you actually use it?
     
    PoPSiCLe, May 1, 2015 IP
  3. ketting00

    ketting00 Well-Known Member

    Messages:
    772
    Likes Received:
    27
    Best Answers:
    3
    Trophy Points:
    128
    #3
    Yes, they aren't in used before data is filled. So the variables are empty if there is no data. I have no idea how to declare these global variables. They will be used in different functions.
     
    ketting00, May 2, 2015 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Honestly if the difference between any of those matters, you are doing something wrong. If you want it global in scope, declare them ANY of those ways outside your functions, and boom you have a global. You don't have to say "null" or "false".

    Though I'd probably NOT be trying to make them global and instead try to isolate their scope or pass the values somehow... but that would depend on how the code you are writing functions and what it is you are actually trying to do -- and just how much framework asshattery is pissing on things.
     
    deathshadow, May 6, 2015 IP
    ketting00 likes this.