Home » Javascript » JavaScript error only on Firefox jQuery.Deferred exception: variablename is undefined

JavaScript error only on Firefox jQuery.Deferred exception: variablename is undefined

Posted by: admin October 29, 2018 Leave a comment

Questions:

I’m getting a weird error only on Firefox. Things working as expected on all other browsers including IE.

The error I’m getting is

jQuery.Deferred exception: first is undefined

$( document ).ready(function() {
    var customer = {{{json customer}}};
    var first = '';
    var second = '';
    var third = '';
    console.log(customer);

    var customer_id = '{{customer.customer_group_id}}';
    customer_id = customer_id * 1;
    console.log(customer_id);
    if(customer_id == 2 || customer_id == null || customer_id == 0){
        console.log('I am running');
        console.log("1 ->" + document.querySelectorAll('.breadcrumbs .breadcrumb')[1]['outerText']);
        var first = document.querySelectorAll('.breadcrumbs .breadcrumb')[1]['outerText'];
        first = first.trim();
        console.log("First ::" + first);
    }
});

The issue seems to have around the trim function.
It still comes up if I try,

var newvariable = first.trim();
Answers: