// Check if the plugin function/method exists
if (typeof $.fn.pluginName !== 'undefined') {
    // Plugin is loaded
    console.log('Plugin is available');
} else {
    console.log('Plugin is NOT loaded');
}

// Alternative syntax
if ($.fn.pluginName) {
    // Plugin is available
}

// For plugins that add methods like .modal(), .carousel(), etc.
if (typeof $.fn.modal === 'function') {
    // Bootstrap modal plugin is loaded
}

if (typeof $.fn.datepicker === 'function') {
    // Datepicker plugin is loaded
}
// Some plugins create global variables
if (typeof jQueryPluginName !== 'undefined') {
    // Plugin global variable exists
}

// Example for specific plugins
if (typeof $.datepicker !== 'undefined') {
    // jQuery UI Datepicker is loaded
}
try {
    // Try to use the plugin
    var test = $.fn.pluginName;
    console.log('Plugin is loaded');
} catch (e) {
    console.log('Plugin is NOT loaded');
}
function isPluginLoaded(pluginName) {
    // Check multiple possible ways the plugin might be exposed
    if ($.fn[pluginName] || $[pluginName] || window[pluginName]) {
        return true;
    }
    return false;
}

// Usage
if (isPluginLoaded('slick')) {
    console.log('Slick slider is loaded');
}

// Check if jQuery itself is loaded
typeof jQuery  // Should return "function"
typeof $       // Should return "function"

// Check specific plugins
$.fn.dataTable  // Check for DataTables
$.fn.select2    // Check for Select2
$.fn.validate   // Check for jQuery Validate



function checkjQueryPlugin(pluginName) {
    // Check if jQuery is loaded first
    if (typeof jQuery === 'undefined') {
        console.error('jQuery is not loaded');
        return false;
    }
    
    // Check different ways plugins expose themselves
    if ($.fn[pluginName]) {
        console.log(pluginName + ' plugin found on $.fn');
        return true;
    }
    
    if ($[pluginName]) {
        console.log(pluginName + ' plugin found on $');
        return true;
    }
    
    if (window[pluginName]) {
        console.log(pluginName + ' plugin found globally');
        return true;
    }
    
    // Check for jQuery UI plugins (they often use .data())
    if ($.ui && $.ui[pluginName]) {
        console.log(pluginName + ' is a jQuery UI plugin');
        return true;
    }
    
    console.log(pluginName + ' plugin NOT found');
    return false;
}

// Usage
checkjQueryPlugin('modal');      // Bootstrap modal
checkjQueryPlugin('datepicker'); // jQuery UI Datepicker
checkjQueryPlugin('slick');      // Slick carousel



// Bootstrap plugins
if ($.fn.modal && $.fn.modal.Constructor) {
    console.log('Bootstrap Modal loaded');
}

// DataTables
if ($.fn.DataTable) {
    console.log('DataTables loaded');
}

// Select2
if ($.fn.select2) {
    console.log('Select2 loaded');
}

// jQuery UI (check version too)
if ($.ui) {
    console.log('jQuery UI loaded, version: ' + $.ui.version);
    if ($.ui.datepicker) {
        console.log('Datepicker widget available');
    }
}


<script src="jquery.js"></script>
<!-- jQuery must load first -->
<script src="jquery-plugin.js"></script>
<!-- Then plugins -->
<script>
    // This will work
    $(document).ready(function() {
        if ($.fn.pluginName) {
            console.log('Plugin ready to use');
        }
    });
</script>

// Check jQuery version
console.log('jQuery version:', $.fn.jquery);

// Check if $ conflicts with other libraries
console.log('$ is jQuery?', $ === jQuery);

// If jQuery is in noConflict mode
var jq = jQuery.noConflict();
if (jq.fn.pluginName) {
    // Use jq instead of $
}