What are 'module' and 'define' in JQuery source code?

This part is a UMD wrapper.

UMD wrapper?

It is meant to support the different methods that are used to import or load libraries. To do so, it is checking if one of the supported module system is available.

In summary, jQuery is checking here how it should define itself before doing so. This way, it supports global insertion as well as the two most common module patterns (commonJS and AMD).

Module pattern?

ES5 and prior did not officially support modules like most languages do (e.g. import my.module in java). As a result, by default it is hard to split your code into different modules or files to keep it well organised.

By default, The only way to import modules is to use the script tag in the HTML and rely on the global context (i.e. window) to link them. It does not check module's dependencies and you have to manually add each source files you depend on (and make sure that the dependencies of a file are inserted before it).

To solve this issue, there is currently 3 main strategies that have been developed so that you can define a module, what it depends on, and what it exports. It allows to automate module and dependencies import:

  1. The commonJS pattern that is originally node's module pattern though it is now also very used with web applications through builders like browserify or webpack. This is the pattern that is using module.exports to define a module (the module is then requested by its consumer with var module = require('modulePath');).
  2. The AMD (Asynchronous Module Definition) module pattern that is the pattern used by RequireJS for example. This is the pattern that is using define (define is used both to request dependencies and define a new module).
  3. And finally, more recently, the ES6 import pattern that will be the way to import modules with next JavaScript's version (actually there is amazing tools such as babel that allows you to already use it). It is not supported in the snippet here (but most ES6 module builders also support the two above-mentioned).