Skip to content
Related Articles

Related Articles

Difference between AngularJS expressions and JavaScript expressions
  • Last Updated : 22 Dec, 2020

Angularjs Expression: Expressions in AngularJS are used to bind application data to HTML. The expressions are resolved by Angular and the result is returned back to where the expression is written. The expressions in AngularJS are written in double braces: {{ expression }}. They behave similar to ng-bind directives: ng-bind=”expression”.


        3 +  3= {{3 + 3}} 
        3 - 3 = {{3 - 3}}
        3 * 3 = {{3 * 3}} 
        3 / 3 = {{3 / 3}}

JavaScript Expression: If a valid set of literals, variables, operators, and expressions that evaluate to a single value that is an expression. This single value can be a number, a string, or a logical value as depending expression. With the concept, there are two types of expressions.

  • Assigned a value to a variable:
    x = 11
  • Simply have a value:
    22 + 11

JavaScript has the following kinds of expressions:

  • Arithmetic: These are the expressions which evaluates to a number.
  • Logical: These are the expressions which evaluates to true or false.
  • String: These are the expressions which evaluates to a character string, for example “Geek” or “987”.

Note: The special keyword null denotes a null value.

Difference between Angular expression and JavaScript expression

Parameter Angularjs expression JavaScript expression
Context Angular expressions are evaluated against a scopeobject. JavaScript expressions are evaluated against the global window.
Forgiving In Angular, expression evaluation is forgiving to undefined and null. JavaScript expression try to evaluate undefined properties generates ReferenceError or TypeError.
Control Flow Statements Control flow statements cannot be used in angularjs expressions,i.e,loop,conditional or exception Control flow statements can be used in JavaScript expressions
Function Declarations Angular Expressions do not allow function declaration,not even inside ng-init directive. function declaration is allowed in JavaScript expressions
Bitwise, Comma, And Void Operators In an Angular expression Bitwise, , or void operators cannot be used. You can use Bitwise, , or void operators in an JavaScript expression.
Filter Angular expressions can work with filter JavaScript expressions do not work with filter
One time binding One time binding is supported by AngularJS. To create one time binding use :: expression. JavaScript expression do not allow one time binding.


My Personal Notes arrow_drop_up
Recommended Articles
Page :