0

In the following

var obj = { one:1, two:2, three:3, four:4, five:5 };
    $.each(obj, function(i, val) {
       console.log(val);
    });

what does $ mean here? Is $ an object?

Adam Lee
  • 24,710
  • 51
  • 156
  • 236
  • Every function in JavaScript is also an object. The `$` in your code refers to the jQuery function, and therefore to the jQuery function *as an object*. The way jQuery is written is such that various utility methods are exposed as properties of the object (that is, properties of the function object). – Pointy Aug 17 '12 at 21:52
  • $ stands for dollars, or in other words mula, cash, money etc. and it's always an object no matter how much you got! – adeneo Aug 17 '12 at 21:54
  • +1 nice question as it is not as obvious (not sure how answer gets +5 but question only +1). In addition to `Xion`'s answer, see this documentation which mentions this too: http://api.jquery.com/jQuery.noConflict/ As stated at the top of the documentation: `Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery's case, $ is just an alias for jQuery, so all functionality is available without using $.` – Nope Aug 17 '12 at 22:17
  • Possible duplicate of [What is the meaning of symbol $ in jQuery?](http://stackoverflow.com/questions/1049112/what-is-the-meaning-of-symbol-in-jquery) – ROMANIA_engineer Jan 09 '16 at 23:47

4 Answers4

5

$ is an alias for jQuery object/function. It's acts as a namespace under which all jQuery functions are stored.

Xion
  • 22,400
  • 10
  • 55
  • 79
1

$ stands for jQuery function/object, you can find good discussion over here

Community
  • 1
  • 1
Adil
  • 146,340
  • 25
  • 209
  • 204
0

http://api.jquery.com/jQuery/

jQuery() — which can also be written as $() — searches through the DOM for any elements that match the provided selector and creates a new jQuery object that references these elements..

-jQuery Site

TyMayn
  • 1,936
  • 2
  • 18
  • 23
  • 1
    That would be the jQuery function, or `$()`, not the jQuery object namespaced `$`, used as an object in `$.each()` even though they are basically the same thing, `$.each()` does not search for elements matcing a selector! – adeneo Aug 17 '12 at 21:56
0

$ is referring to the jQuery function.

In JavaScript, a function is a special kind of object.

You can create a function and add properties to it like any other object.

var $ = function(message) { alert(message); };

$.prop1 = 'val1';
$.prop2 = 'val2';

$("Hello world");

alert($.prop2);

alert($ instanceof Object);   /* This will be "true" */
alert($ instanceof Function); /* This will be "true" */
gray state is coming
  • 2,107
  • 11
  • 20