-1

What does the $ before the function mean in Javascript? I found this in a Javascript script for a Chromium extension.

$(function() {
  $('#search').change(function() {
     $('#bookmarks').empty();
     dumpBookmarks($('#search').val());
  });
});
Matt
  • 3
  • 2

3 Answers3

2

This looks like jQuery but could also be any number of web frameworks.

$ is simply a variable (in this case a function) name, just like any other JavaScript variable name. It likely is also available and aliased as jQuery.

You can confirm and see the version using the below in a browser's developer console while on the website.

$ === jQuery
> true
$.fn.jquery
> "1.12.1"
Chase
  • 3,028
  • 14
  • 15
1

It means it is a function of a JQuery object, a popular javascript library

Lucca Bibar
  • 141
  • 1
  • 1
  • 10
0

This could be an Immediately-invoked Function Expressions with jQuery. $ is equal to 'jQuery'. With the immediate function, you can define variables inside the context of the function and avoid global variable definitions. As soon as jQuery loads this function executes.

Nuwan.Niroshana
  • 407
  • 4
  • 15