1

I don't understand why I can't do

openAndFillModalSoin(soin)
        {
            this.show = true,   

            this.vDate = soin.date,
            this.vCategorie = soin.categoriesoin.name,
            //This can be null
            if(soin.rabaisraion){
                this.vReasonReduction = soin.rabaisraison.id;
            }

            this.vPaiement = soin.moyendepaiement.nam,
            this.vRefer = soin.referedBy,
            //This can be null aswell
            this.vGiftCard = soin.boncadeau.id,
            this.vVoucher = soin.bonreduction.id;

            this.vID = soin.id;
        },

The "if" parts doesn't work, it asks for an expression.

If in method

3 Answers 3

2

You have commas instead of semicolons ending the preceding line.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I'm sorry I'm having trouble with the use of semicolons and commas in js
1
if(soin.rabaisraion){
                this.vReasonReduction = soin.rabaisraison.id;
            }

This this code will run when the following is NOT TRUE soin.rabaisraion is the number 0, false, null, undefined, or an empty string.

To reiterate, the string 'false', the string '0' and and an array (empty or not) are all true.

Also, if soin is null or undefined, that will be a runtime error.

Perhaps you want this:

if(soin && soin.rabaisraion){
   this.vReasonReduction = soin.rabaisraison.id;
}

Regardless, add a log before to see what's going on:

console.log('checking soin', soin)
console.log('checking boolean soin', !!soin)
if(soin && soin.rabaisraion){
   this.vReasonReduction = soin.rabaisraison.id;
}

The '!!' will force the value to boolean.

1 Comment

Actually, I can't even compile. I'll add a screen in edit
0
//check undefined Array
if (typeof myArray === "undefined") {
    alert("myArray is undefined");
}

// check undefined object
if (typeof myObj === "undefined") {
    alert("myObj is undefined");
}

//check object property
if (typeof myObj.some_property === "undefined") {
    alert("some_property is undefined");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.