0

so plz forgive me for my silly question, I know "$" is a shortcut for jQuery, but I've been seen some code like:

  var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>",
  xmlDoc = $.parseXML( xml ),
  $xml = $( xmlDoc ),
  $title = $xml.find( "title" );

so my questions are:

  1. How come there is no "var" prefix for xmlDoc? shouldn't it be:

    var xmlDoc = $.parseXML( xml )?

2.what does the "$" in $xml stands for? if xml is a variable, shouldn't it be:

var xml = $( xmlDoc )?
  • 1
    Possible duplicate of [What is the meaning of "$" sign in javascript](https://stackoverflow.com/questions/1150381/what-is-the-meaning-of-sign-in-javascript) – OmG Jul 16 '17 at 14:10

2 Answers2

1
  1. no "var" prefix for xmlDoc is valid, it is using short syntax of variable declaration (see ,). Even if there were no , it'll declare a global javascript variable.

  2. "$" in $xml changes nothing, $xml is a valid variable name just like other variable names.

vatz88
  • 2,422
  • 2
  • 14
  • 25
0

There might be other libraries also using jQuery shortcut $. This link might help better understand shortcut for jQuery:

http://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/

Richard Mneyan
  • 656
  • 1
  • 13
  • 20