[Vuejs]-Strict comparison not producing expected result in production environment but works well on local server

0👍

That means that your code/config/etc. in production is creating a string, or a number object (rather than primitive), or some other kind of object that when coerced to number coerces to one of your expected values.

Example with a string:

function strict(type) {
    switch(type)
    {
        case 1:
            return 'Request Quote';
        case 2:
            return 'Negotiate';
        case 3:
            return 'Fixed';
        default:
            return 'matched none';
    }
}

function loose(type) {
    if(type == 1) return 'Request Quote';
    else if(type == 2) return 'Negotiate';
    else if(type == 3) return 'Fixed';
    else return 'matched none';
}

var n;
console.log("Number:");
n = 2;
console.log("strict", strict(n));
console.log("loose", loose(n));

console.log("String:");
n = "2";
console.log("strict", strict(n));
console.log("loose", loose(n));

Example with a number object:

function strict(type) {
    switch(type)
    {
        case 1:
            return 'Request Quote';
        case 2:
            return 'Negotiate';
        case 3:
            return 'Fixed';
        default:
            return 'matched none';
    }
}

function loose(type) {
    if(type == 1) return 'Request Quote';
    else if(type == 2) return 'Negotiate';
    else if(type == 3) return 'Fixed';
    else return 'matched none';
}

var n;
console.log("Primitive:");
n = 2;
console.log("strict", strict(n));
console.log("loose", loose(n));

console.log("Number object:");
n = new Number(2);
console.log("strict", strict(n));
console.log("loose", loose(n));

You’ll have to find out what is different in the environment/code/config such that you’re ending up with the wrong kind of value for this.job.type.

0👍

Check your variable type, I think you’re getting a string in production too.

I suggest you using Typescript or Flowtype to avoid those check.

Leave a comment