I created a button which will update SAPReleased__c only if Approved__c is true(SAPReleased__c and Approved__c are both check boxes). What I don't understand is.. Why is this working!??

        if(sampling.Approved__c == 'true'){ 
        alert('Inside condition');  
        sampling.SAPReleased__c = true; 

        }else if (sampling.Approved__c == 'false'){ 
        alert('Sample must be approved before it can be booked.'); 
        var result = sforce.connection.update([sampling]); 

Now look at my conditions

if(sampling.Approved__c == 'true')
else if (sampling.Approved__c == 'false')

This doesn't make any sense to me? I am checking to see if they are 'true' or 'false', but isn't this checking to see if its a String of true or false while it should be expecting a boolean?

Is this an expected outcome or is this something cooky?

1 Answer 1


This is working because Javascript is doing the type conversion for you. You need to use a '===' to strictly evaluate a boolean like true or false. With a '==' as I understand it, type conversion has to occur before the comparison can be evaluated and type conversion can lead to strange results. In this case though, it's leading to your intended result, which is conversion from boolean to string and the correct evaluation.

Here is a pretty good blog post explaining different equals operators in Javascript: Why Use the Triple-Equals Operator in JavaScript?

  • 1
    It is so I will leave alone, it's just very interesting..
    – EricSSH
    Apr 14, 2014 at 22:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .