Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When using an undefined/undeclared variable it doesn't throw any exceptions, but using it's properties does. This is where it gets a bit fuzzy though. </p> <p>If you check for the existence of this undeclared variable by <em>typeof</em>, it evaluates to <strong>false</strong> (at least I think so, it does so when being the only condition...) and does not continue to check for further conditions. If you only check for it's existence by it's name, it evaluates to false, but the next condition gets evaluated none the less... </p> <p>Anyhow, this does not throw any exception:</p> <pre><code>if(typeof undeclaredVariable !== "undefined" &amp;&amp; typeof undeclaredVariable.property !== "undefined") { // this works just fine } </code></pre> <p>and neither does:</p> <pre><code>if(typeof undeclaredVariable !== "undefined" &amp;&amp; undeclaredVariable.property) { // this also works just fine but is shorter } </code></pre> <p>but this does:</p> <pre><code>if (undeclaredVariable &amp;&amp; undeclaredVariable.property) { // the conditional clause does not stop at undeclaredVariable but also checks for undeclaredVariable.id where it throws an exception } </code></pre> <p>Without understanding the true mechanisms of how conditions get evaluated, the answer to my question is (successfully tested):</p> <pre><code>{{if typeof payment_method !== "undefined" &amp;&amp; payment_method &amp;&amp; (payment_method.id == $value.id)}} </code></pre> <p><strong>EDIT</strong>: Using an undefined/undeclared variable throws an exception in js, but it does not in jQuery tmpl.</p> <p>js:</p> <pre><code>if (undeclaredVariable) { // throws an exception } </code></pre> <p>jQuery tmpl:</p> <pre><code>{{if undeclaredVariable}} // evaluates to false, but does not throw an exception {{/if}} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload