What is the difference between adding $ and not adding $ to variables in jquery?

No difference, just habit. Generally, when naming a jQuery object, add $ in front. At first glance, you can tell that it is a jquery object.

The starting characters in the variable naming rules can be letters, underscores (_), and dollar signs ($), but many js libraries like to use $ as the global variable mark.

jQuery is no exception. Adding $ makes it easier to distinguish as a jQuery variable mark.

When using jQuery, if a variable is wrapped by $();. Then it means that this variable needs to be packaged into a jQuery object before it can be used.

Variables created in jQuery’s own scope do not need to be wrapped with $();. Take a very simple example: for example, a this pointer in js. If this pointer needs to be used in jQuery, then you need to use $(); to wrap it into an object in jQuery, you need to write it like this: $(this).

If one variable is named $xxx, and another variable is named xxx. Well this is a good coding practice. It is to distinguish between variables created using jQuery and variables created by javascript itself.