JavaScript: variables, operators, statements, keywords, comments, data types, functions, capitalization, and naming rules

1, JavaScript digital

In programming languages, it is generally referred to as literal constant value, such as 3.14.

Number (Number) may be a literal integer or decimal, or scientific notation (e).

<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 123e5;
</script>

2, the string may be used single or double quotes:

<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 'John Doe';
</script>

3, for calculating the expression:

<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 * 10;
</script>

4, the array (the Array)

Define an array:

[40, 100, 1, 5, 25, 10]

5, the object (Object)

The definition of an object:

{firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"}

6, the function (Function)

The definition of a function:

function myFunction(a, b) { return a * b;}

7, JavaScript variables

In programming languages, variables are used to store data values.

JavaScript var keyword to define variables, use the equal sign to assign a variable:

<p id="demo"></p>
<script>
var length;
length = 6;
document.getElementById("demo").innerHTML = length;
</script>

8, JavaScript operator

Using the arithmetic operators to JavaScript Calcd:

<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = (5 + 6) * 10;
</script>

9, JavaScript using the assignment operator assign values ​​to variables:

<p id="demo"></p>
<script>
var x, y, z;
x = 5;
y = 6;
z = (x + y) * 10;
document.getElementById("demo").innerHTML = z;
</script>

10, assignment, arithmetic and bitwise operators

=  +  -  *  /

Conditions and logical operators Comparison

==  != <  >  

11, JavaScript statements

In HTML, JavaScript statement is a command to your browser.

Statements are separated by semicolons:

x = 5 + 6;
y = x * 10;

12, JavaScript keyword

JavaScript keyword is used to identify the operation to be performed.

And any other programming languages, JavaScript retain some keywords for their own use.
var keyword tells the browser to create a new variable:

var x = 5 + 6;
var y = x * 10;

13, JavaScript comments

Not all JavaScript statements are "command." // double slash contents of the browser will be ignored:


// 我不会执行

14, JavaScript Data Types

JavaScript has multiple data types: numeric, strings, arrays, and the like objects:

var length = 16;                                  // Number 通过数字字面量赋值
var points = x * 10;                              // Number 通过表达式字面量赋值
var lastName = "Johnson";                         // String 通过字符串字面量赋值
var cars = ["Saab", "Volvo", "BMW"];              // Array  通过数组字面量赋值
var person = {firstName:"John", lastName:"Doe"};  // Object 通过对象字面量赋值

15, JavaScript letter case

JavaScript is case-sensitive.

When you write JavaScript statements, please pay attention to whether to close the case toggle key.

GetElementById function and getElementbyID is different.

Similarly, the variable myVariable and MyVariable is different.

16, JavaScript naming rules

Common hump naming method, such as lastName (instead of lastname).

Guess you like

Origin blog.csdn.net/weixin_43731793/article/details/92075228