SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2004
    Location
    Texas
    Posts
    433
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Very basic javascript question! Newbie alert!

    So, I'm teaching myself javascript basics and had a question:

    When I write something like

    Code:
    var $fullName = $firstName + ' ' + $lastName;
    Why do i have to have 2 '+' operators instead of just one? I thought you write it like

    Code:
    var $fullName = $firstName + ' ' $lastName;
    Thank you.

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,002
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hey skunker,

    You write it with two pluses because you are concatenating three strings: $firstName, a space and $lastName.

    PPK has a good explanation of this: http://www.quirksmode.org/js/strings.html#conc

    HTH


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •