In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today I'll show you what the expression in JavaScript is. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.
In JavaScript, expressions are a combination of meaningful permutations of numbers, operators, numeric grouping symbols (parentheses), free variables and constrained variables to obtain numerical values; expressions can be divided into two types: original expressions and complex expressions.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Generally speaking, the terms that people hear more about the basic syntax of javascript are operators and statements. However, there is another term that is often used but rarely mentioned, and that is javascript expressions (expression). This article will introduce javascript expressions in detail
What is an expression?
An expression is a combination of numbers, operators, numeric grouping symbols (parentheses), free variables, and constrained variables in order to obtain numerical values. A constraint variable is assigned a numeric value in the expression, while a free variable can specify a numerical value in addition to the expression.
Javascript expressions are divided into original expressions and complex expressions.
Original expression (primary exression)
The original expression is the smallest unit of the expression-it no longer contains other expressions
The original expression is divided into literals, keywords and variables; in detail, it includes this keywords, identifier references, literal references, array initialization, object initialization, and grouping expressions
PrimaryExpression: this Identifier Literal ArrayLiteral ObjectLiteral (Expression)
This keywords and identifiers
This;// returns the current object ibank / the value of variable I sum;// returns the value of variable sum
Literal quantity
Literal quantity (literal), which is translated into direct quantity, is the data value used directly in the program.
Literal:: NullLiteral BooleanLiteral NumericLiteral StringLiteral RegularExpressionLiteralnull;undefined;true;false;1;'abc';/pattern/
Array and object initialization
Array initialization and object initialization are actually a literal initialization process. These two initialization expressions are sometimes called "object literals" and "array literals"
[]; [1Jing 2jue 3]; {}; {aVue 1}
Grouping expression
Grouping expressions are actually parentheses that override the precedence of the operator
Complex expression (MemberExpression)
Complex expressions are composed of primitive expressions and operators (operator), including attribute access expressions, object creation expressions, and function expressions
MemberExpression: MemberExpression [Expression] MemberExpression. IdentifierName new MemberExpression ArgumentsFunctionExpression
Attribute access expression
The attribute access expression operation can get the value of an object attribute or an array element. Javascript defines two syntax for attribute access.
MemberExpression. IdentifierName MemberExpression [Expression]
The first way to write is an expression followed by a period and an identifier. The expression specifies the object, and the identifier specifies the name of the attribute to be accessed
The second way to write is to use square brackets, inside which is another expression (this method applies to objects and arrays). The second expression specifies the name of the attribute to access or the index that represents the element of the array to be accessed
Var o = {XRO 1Magi y: {ZGV 3}}; / object literals var a = [OMague 4, [5je 6]]; / / contains the array literals of the object o.xlechange / the x attribute of the expression o .y.z leading / the z attribute o of the expression o.y [x']; / the x attribute a [1] of the object o; / the element with index 1 in expression a
No matter which form of attribute access expression is used, in'.' Expressions before'['and' ['always evaluate first
If it evaluates to null or undefined, the expression throws a type error exception because neither of these values can contain any attributes
If the result of the calculation is not an object, javascript converts it to an object
If the object expression is followed by a period and an identifier, the attribute value specified by that identifier is found and returned as the value of the entire expression
If the object expression is followed by a square bracket, the value of the expression in square brackets is calculated and converted to a string
In either case, if the named attribute does not exist, the value of the entire attribute access expression is undefined
Object creation expression
Object creation expression creates an object and calls a function to initialize the properties of the new object
New Object (); new Point (2pr 3)
If an object creation expression does not need to pass any parameters to the constructor, then this pair of empty parentheses can be omitted
New Object
Function expression
Function expressions are divided into function definition expressions and function call expressions.
Function definition expression defines a javascript function whose value is the newly defined function
A typical function definition expression contains the keyword function, followed by a pair of parentheses, with a comma-separated list containing 0 or more identifiers (parameter names), followed by a javascript code snippet (function body) wrapped in curly braces.
Function square (x) {return x;}
A function definition expression can also contain the name of a function, and a function can also be defined by a function statement rather than a function expression
Var square = function (x) {return x;}
A function call expression is a grammatical representation that calls or executes a function or method. If the expression is an attribute access expression, then the call is called a method call
F (0); Math.max (xrecoveryjournal z); a.sort (); that's all about what the expression in JavaScript is all about. More related to what the expression in JavaScript is, you can search the previous article or browse the following article to learn! I believe the editor will add more knowledge to you. I hope you can support it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.