JavaScript syntax
avaScript is a programming language. Grammar rules define the structure of a language.
JavaScript Syntax
JavaScript is a scripting language.
It is a lightweight, yet powerful programming language.
JavaScript Literal
In a programming language, a literal is a constant, as in 3.14.
Number literal can be an integer or a decimal, or scientific notation (e).
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = 123e5; </script> </body> </html>
Run the program and try it
String literal You can use single quotes or double quotes:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <p id="demo">andy</p> <script> document.getElementById("demo").innerHTML = 'liu qi'; </script> </body> </html>
Run the program and try it
Expression literals are used for calculations:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = 5 * 10; </script> </body> </html>
Run the program and try it
Array (Array) literals define an array:
[40, 100, 1, 5, 25, 10]
Object literal defines an object:
{firstName: "John", lastName:"Doe", age:50, eyeColor:"blue"}
Function (Function) literal defines a function:
function myFunction(a, b ) { return a * b;}
#JavaScript Variable
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <p id="demo"></p> <script> var length; length = 6; document.getElementById("demo").innerHTML = length; </script> </body> </html>Run the program and try it
JavaScript Operator
JavaScript uses arithmetic operators to calculate values:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = (5 + 6) * 10; </script> </body> </html>Run the program to try it
JavaScript uses assignment operators to variables Assignment:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <p id="demo"></p> <script> var x, y, z; x = 5 y = 6; z = (x + y) * 10; document.getElementById("demo").innerHTML = z; </script> </body> </html>Run the program and try it
The JavaScript language has many types of operators:
Instance | Description | ||
---|---|---|---|
= + - * / | Description in JS operators | ||
== != < > | Comparison in JS Operators are described in |
abstract | else | instanceof | super |
boolean | enum | int | switch |
break | export | interface | synchronized |
byte | extends | let | this |
case | false | long | throw |
catch | final | native | throws |
char | finally | new | transient |
class | float | null | true |
const | for | package | try |
continue | function | private | typeof |
debugger | goto | protected | var |
default | if | public | void |
delete | implements | return | volatile |
do | import | short | while |
double | in | static | with |
JavaScript 对大小写敏感。
JavaScript 对大小写是敏感的。
当编写 JavaScript 语句时,请留意是否关闭大小写切换键。
函数 getElementById 与 getElementbyID 是不同的。
同样,变量 myVariable 与 MyVariable 也是不同的。
- Course Recommendations
- Courseware download
-
ElementaryImperial CMS enterprise imitation website tutorial
3048 people are watching -
ElementaryNewbies with zero foundation in WordPress build personal blogs and corporate websites
6743 people are watching -
ElementaryUltimate CMS zero-based website building instruction video
2724 people are watching -
ElementaryFront-end project-Shangyou [HTML/CSS/JS technology comprehensive practice]
3117 people are watching -
IntermediateVue3.0 from 0 to build a universal backend management system project practice
5351 people are watching -
ElementaryZero-based front-end course [Vue advanced learning and practical application]
2821 people are watching -
ElementaryWEB front-end tutorial [HTML5+CSS3+JS]
3506 people are watching -
ElementaryQuick introduction to apipost
2161 people are watching -
IntermediateVue3+TypeScript practical tutorial-enterprise-level project practice
3208 people are watching -
ElementaryLet's briefly talk about starting a business in PHP
17423 people are watching -
IntermediateVUE e-commerce project (front-end & back-end dual project actual combat)
3828 people are watching -
ElementaryApipost practical application [api, interface, automated testing, mock]
2265 people are watching
Students who have watched this course are also learning
- Let's briefly talk about starting a business in PHP
- Quick introduction to web front-end development
- Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
- Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
- Login verification and classic message board
- Computer network knowledge collection
- Quick Start Node.JS Full Version
- The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
- Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)