Magento 2
Create an AMD JavaScript Component
Free Preview
app/code/Foo/Bar/view/frontend/web/js/my-test.js
// Call the "define" function to create an AMD JavaScript component

// The first parameter expects an array of dependencies
// The second parameter is a function which maps those dependencies to variables

// In this case, 'jquery' maps to the '$' variable
define(['jquery'], function($) {
    // Encapsulating code within functions avoids polluting the global namespace
    // Code within this block is inaccessible globally
    
    // Since '$' was passed into this function, it can be accessed in this block
    // You can then execute any code you wish or return a function for later use
    $(function() {
        console.log('page ready');
    });
});
Want to learn more?

Visit M.academy to learn much more about Magento, Laravel, PHP, Javascript, & Docker.

M.academy logo