Answers.Body: <p>Generally speaking, no. They are just two ways of saying the same thing.</p>
  
  <p>Dot syntax is necessary when you are referring to a <strong>method</strong> within an object. However, if you are only trying to access the <strong>property</strong> of an object (or a value within an array), either technique will work.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-14T17:35:30.257Z
Answers.LastActivityDate: 2014-06-14T17:35:30.257Z
Answers.UserDisplayName: Lindsey D
Answers.Body: <p>They're both the same for the most part.</p>
  
  <p>The only time I'd use the second way you listed is when the property is a variable.</p>
  
  <p>For instance:</p>
  
  <pre><code>{% set foo = 'name' %}
  {{ variable[foo] }}
  </code></pre>
  
  <p>This will give you <code>{{ variable.name }}</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-14T17:37:54.743Z
Answers.Text: Yes, using property as a variable is definitely important thing! +1
Answers.UserDisplayName: nicael
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-14T17:36:20.490Z
Answers.LastActivityDate: 2014-06-14T17:41:45.213Z
Answers.LastEditDate: 2014-06-14T17:41:45.213Z
Answers.UserDisplayName: Bill Criswell
Body: <p>When to use</p>
  
  <pre><code>{{ variable.property }}
  </code></pre>
  
  <p>and when to use</p>
  
  <pre><code>{{ variable['property'] }}
  </code></pre>
  
  <p>Is there a difference between these methods of accessing attributes of a variable or advantages of using one of them?</p>
  
Tags: <variable><difference><attribute>
Title: Difference between using subscript syntax and "dot" syntax when accessing attributes of a variable or advantages of usage one of them
ThreadText: # Difference between using subscript syntax and "dot" syntax when accessing attributes of a variable or advantages of usage one of them
  
  (Asked by: username_0 on 2014-06-14)
  
  When to use
  
  ```
  {{ variable.property }}
  
  ```
  
  and when to use
  
  ```
  {{ variable['property'] }}
  
  ```
  
  Is there a difference between these methods of accessing attributes of a variable or advantages of using one of them?
  
  **Tags:** variable, difference, attribute
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2014-06-14. Score: 7 | Accepted answer
  
  They're both the same for the most part.
  
  The only time I'd use the second way you listed is when the property is a variable.
  
  For instance:
  
  ```
  {% set foo = 'name' %}
  {{ variable[foo] }}
  
  ```
  
  This will give you `{{ variable.name }}`
  
  > **Comments:**
  > **username_0**: Yes, using property as a variable is definitely important thing! +1  
  
  ---
  
  ### Answer by username_1 on 2014-06-14. Score: 4
  
  Generally speaking, no. They are just two ways of saying the same thing.
  
  Dot syntax is necessary when you are referring to a **method** within an object. However, if you are only trying to access the **property** of an object (or a value within an array), either technique will work.
  
  
  ---
  
  