Skip to content
Related Articles

Related Articles

Improve Article

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”.

Example:

   <div>
        3 +  3= {{3 + 3}} 
        3 - 3 = {{3 - 3}}
        3 * 3 = {{3 * 3}} 
        3 / 3 = {{3 / 3}}
   </div>

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

ParameterAngularjs expressionJavaScript expression
ContextAngular expressions are evaluated against a scopeobject.JavaScript expressions are evaluated against the global window.
ForgivingIn Angular, expression evaluation is forgiving to undefined and null.JavaScript expression try to evaluate undefined properties generates ReferenceError or TypeError.
Control Flow StatementsControl flow statements cannot be used in angularjs expressions,i.e,loop,conditional or exceptionControl flow statements can be used in JavaScript expressions
Function DeclarationsAngular Expressions do not allow function declaration,not even inside ng-init directive.function declaration is allowed in JavaScript expressions
Bitwise, Comma, And Void OperatorsIn an Angular expression Bitwise, , or void operators cannot be used.You can use Bitwise, , or void operators in an JavaScript expression.
FilterAngular expressions can work with filterJavaScript expressions do not work with filter
One time bindingOne 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 :