Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

JavaScript basic syntax


May 29, 2021 Article blog


Table of contents


JavaScript's getting started is syntax content, so you can follow up, and this article tells you the basic syntax of JavaScript

JavaScript basic syntax

The combination of JS and HTML

1, internal JS, we can define a <script > tag, <script > content is js code, can also be defined anywhere in the HTML page, but may affect the order of execution

2, external JS, or define a <script > through the src property to introduce external JS

exegesis

Single-line comment://comment

Multi-line comments: / . . . comments . . .

data type

Original data type:

number: integer, decimal, NaN

String: String, regardless of single double quotes

Boolean: Boolean value, true/false

null: An object is an empty placeholder

Undefined: Undefined, uninitialized variables default to undefined

variable:

var 变量名=初始化值
document.write(typeof(变量名))//null的类型是object

operator

Monsoun operator:

++   --  +(正号)

binary operator:

+ -  *  /   %

Assignment operator:

+=   -=   *=     /=

Comparison operator:

< <= > >= ==   类型相同直接比较,类型不同转换成相同类型后比较
===    类型不同直接返回false

Logical operators:

&&(与)   ||()或    !(非)   具有短路效果

Troundy operator:

a>b ?a:b


That's all the editor-in-chief has to say about JavaScript's basic syntax