Why is this ok?

Discussion in 'JavaScript' started by askscript, Nov 13, 2008.

  1. #1
    I read that this is a valid JS statement:

    if(var == 4)

    All along i thought that if you use "var", you got to tag to something like this

    var final = 4 , so if (var final ==4) should be correct?

    is there anyone to explain? thks

    Beginner. askscript
     
    askscript, Nov 13, 2008 IP
  2. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Well...

    I haven't ever thought about that before, and I don't know why you would use it. Maybe some browsers will parse it incorrect?

    Where are you reading that? Don't you think they just mean that "var" is the name of your variable?
     
    elias_sorensen, Nov 14, 2008 IP
  3. rene7705

    rene7705 Peon

    Messages:
    233
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    var is a reserved word in javascript, like 'if', 'then', 'else', 'switch', 'case', etc.
    and it's a bad idea to use it as a custom variable name, even if it works.
     
    rene7705, Nov 14, 2008 IP