What are javascript expressions?

藏色散人
Release: 2022-01-19 14:47:06
Original
4093 people have browsed it

Javascript expressions include: 1. Arithmetic expression; 2. String expression; 3. Main expression; 4. Array and object initializer expression; 5. Logical expression; 6. Left-hand expression Formula; 7. Property access expression; 8. Object creation expression; 9. Function definition expression; 10. Call expression, etc.

What are javascript expressions?

The operating environment of this article: Windows 7 system, javascript version 1.8.5, DELL G3 computer

What are the javascript expressions?

An expression is a unit of code that can be evaluated and resolved into a value. Expressions in JS can be divided into several categories.

  • Arithmetic expression

  • String expression

  • Main expression

  • Array and object initializer expressions

  • Logical expression

  • Left side expression

  • Property access expression

  • Object creation expression

  • Function definition expression

  • Calling expressions

  • Arithmetic expressions

Under this category, take all expressions that evaluate to a number:

1 / 2 i++ i -= 2 i * 2
Copy after login

String expression

Expression that evaluates to a string:

'A ' + 'string'
Copy after login

Main expression

Under this category, variable reference, literal and constants:

2 0.02 'something' true false this //the current object undefined i //where i is a variable or a constant
Copy after login

There are also some language keywords:

function class function* //the generator function yield //the generator pauser/resumer yield* //delegate to another generator or iterator async function* //async function expression await //async function pause/resume/wait for completion /pattern/i //regex () // grouping
Copy after login

Array and object initializer expressions

[] //array literal {} //object literal [1,2,3] {a: 1, b: 2} {a: {b: 1}}
Copy after login

Logical expressions

Logical expressions Use logical operators and resolve to Boolean values:

a && b a || b !a
Copy after login

Left side expression

new //create an instance of a constructor super //calls the parent constructor ...obj //expression using the spread operator
Copy after login

Property access expression

object.property //reference a property (or method) of an object object[property] object['property']
Copy after login

Object creation expression

new object() new a(1) new MyRectangle('name', 2, {a: 4})
Copy after login

Function definition expression

function() {} function(a, b) { return a * b } (a, b) => a * b a => a * 2 () => { return 2 }
Copy after login

Calling expression

Syntax for calling a function or method

a.x(2) window.resize()
Copy after login

Recommended learning: "js basic tutorial"

The above is the detailed content of What are javascript expressions?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!