---
schema_version: "1"
id: 2591473313ac97119d4bf6fe2db50a9464e56b61bc6dda5561c9dcb9dfc4938c
title: Expression Evaluation
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/expr/expr-eval.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/expr-eval.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 25907659c7b12354f5dc6cec77ad5071917ecc6b89cf37566dbb651b0019fc1b
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Expression Evaluation

Expressions are evaluated much the same way that expressions in JavaScript or other programming languages are evaluated.

Operators are a subset of those available in JavaScript, and evaluation order and precedence are generally the same as JavaScript. Parentheses enable you to ensure a specific evaluation order. What you may find surprising about expressions is how often they are evaluated. The framework notices when things change, and triggers re-rendering of any components that are affected. Dependencies are handled automatically. When a component is re-rendered, any expressions it uses will be re-evaluated.

## Action Methods

Expressions are also used to provide action methods for user interface events: `onclick`, `onhover`, and any other component attributes beginning with "`on`".

Action methods must be assigned to attributes using an expression, for example `{!c.theAction}`. This expression assigns a reference to the controller function that handles the action.

Assigning action methods via expressions allows you to assign them conditionally, based on the state of the application or user interface. For more information, see [Conditional Expressions](https://developer.salesforce.com/docs/platform/aura-platform/guide/expr-conditional.md#conditional-expressions).

```nolang
<aura:component>
    <aura:attribute name="liked" type="Boolean" default="true"/>
    <lightning:button aura:id="likeBtn"
     label="{!(v.liked) ? 'Like It' : 'Unlike It'}"
     onclick="{!(v.liked) ? c.likeIt  : c.unlikeIt}"
    />
</aura:component>
```

This button will show "Like It" for items that have not yet been liked, and clicking it will call the `likeIt` action method. Then the component will re-render, and the opposite user interface display and method assignment will be in place. Clicking a second time will unlike the item, and so on.

**note:** The example demonstrates how attributes can help you control the state of a button. To create a button that toggles between states, we recommend using the `lightning:buttonStateful` component.

## Action Methods with Lightning Web Components

If you try to use an action method with a Lightning web component, it doesn’t behave as expected because Lightning web components don’t support expressions the same way that Aura components do. To write an action method, assign a controller action and execute logic depending on a value.

```nolang
<aura:component>
    <aura:attribute name="liked" type="Boolean" default="true"/>
    <c:lwcButton aura:id="likeBtn"
     label="{!(v.liked) ? 'Like It' : 'Unlike It'}"
     onclick="{!c.handleLikeButtonClick}"
    />
</aura:component>
 
```

```nolang
({
    handleLikeButtonClick: function (cmp) {
        if (cmp.get('v.liked')) {
             // like it logic
        } else {
             // unlike it logic
        }
    }
})
```

