Web Analytics Made Easy -
StatCounter Using Space in Variables - CodingForum


No announcement yet.

Using Space in Variables

  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Space in Variables

    I'm using a variable "YesBoss" in my JS file.
    Please tell me how can I give a space within "Yes" and "Boss"???
    I actually want...

    var=Yes Boss
    instead of...

    Please help

  • #2
    Are you trying to declare a variable, or are you trying to set a value? I noticed you used var=YesBoss. Is it really important that you have a space? Assuming You are trying to declare a variable, then It's not possible. If you're trying to make a variable equal to "Yes Boss", then type "var example = "Yes Boss".

    If you're declaring a variable, I don't see how it would matter if there was a space or not, because you could just use "Yesboss", and it wouldn't make a difference.
    var currentTime = new Date()
    var chance = currentTime.getTime()
    var chance2 = chance % 3


    • #3
      You may use an underscore, spaces are not alowed in the name of a function, variable, method...

      var Yes_Boss

      But, really, why do you need a space or a separator?
      Offshore programming


      • #4
        Or var yes, boss='Yes Boss';
        Last edited by mrhoo; Sep 28, 2006, 10:44 AM.


        • #5
          You need to understand the difference between variables and values to ask this question in a way we can all understand.

          A variable is a symbol that the program uses to hold a value. So in the following example:
          var x = 5;
          The variable x has a value of 5. This is similar to algebra, where 1 + x = 6, x has a value of 5.

          It is not possible to create a variable with a space character in the name of the variable like:
          var yes boss = 5;
          because JavaScript (and most other languages) use the space character to separate individual symbols. However, it seems like you're trying to assign a String value to a variable like so:
          var x = "This is a string.";
          All strings must be wrapped in quotes to specify that these are strings. If you were to do this:
          var x = this is a string;
          JavaScript will attempt to figure out the value of this, is, a, and string as if they were separate variables, and since there are no operators between each symbol, it won't know what to do with them anyway.

          I hope this helped you out, and if you need more clarification, just ask.