First of all: jQuery (or its alias $ ) is a function. This is very important because functions are first-class objects in JavaScript. And since they themselves are objects, they have the ability to obtain properties and methods just like any other object. For instance:
var f = function() {}; fh = function(x) { console.log(x); };
This is what allows jQuery to work with magic. In addition, through the use of inheritance, we have the potential for chain methods, as shown in the first example. $(selector) returns the "jQuery" interface (technically [object Object] ) based on the value of selector , from which we can run methods such as .html , .css and .toggle to name a few.
source share