Basic knowledge of JavaScript

JavaScript is doing?

HTML is the basic page (text Images)
CSS by controlling the layout and style make Web pages more attractive
JavaScript is to add animation to web pages and other interactive events, so the page becomes more lively.
JavaScript programming language with about the same, but it is not a programming language, it is a scripting language that runs without compiling directly interpreted by the interpreter to execute. It also has variable functions.

JavaScript features:

1, the grammar is relatively simple (weakly typed variable type)

2, cross-platform (JavaScript scripting language does not depend on the operating system, you need only supported browsers)

 

Writing of a JavaScript code

<script type="text/javascript">
            
            alert("Hello World!!");
        </script>

Renderings implementation:

 

 

 

Write js code in three ways

The first embodiment: the page (the page can be placed anywhere)

<script type="text/javascript">
</script>

The second way: Inline introduction (be introduced by way of the event)

<font onclick = " Alert ( 'you hit me') " > Hello </ font>

Click the effect of hello:

 

 

 


The third embodiment: embodiment externally introduced

<script type="text/javascript" src="test.js" ></script>

 

 

What is the function?

A function has its own a fixed function, call the function equivalent to calling this function. The system functions have built-in functions, we can also define your own functions, we use this function to achieve the desired functionality.
In the function definition, we need to write many lines of code to achieve our desired functionality.
Function can be called multiple times, we only need to call a function in response to calls by the function name, thus avoiding every time you want to call a function, and went to write duplicate code.

Action functions:
1, a function to achieve a fixed function
2, to avoid duplication of writing code

How function call?
xxx1 (arg1, arg2, arg3) ;
function name is defined when the decision, it is time to define the parameters of the decision. We want what we must call the function corresponding to the function name, and provides the corresponding parameters. (Others call a function of time, can not own just write function name and parameter)

 

What is a string?

Several characters (English characters or Chinese characters or special symbols such as a comma) together to form a string, the string is.
Is a string data type in JavaScript.
Data in JavaScript What are they?

(Strings, numbers, images, etc. These are the results of a calculation data)
for each data type has its own data, different data types have different storage in memory. We just need to tell the interpreter what type of data is a data, do not ignore how stored in memory. Interpreter (browser) automatically according to the type of this data, stores it in the memory in response manner.

JavaScript specification string in
a string must use single quotes or double quotes.

When to use single quotes, double quotes when it?
(1) using only the character string (string does not include single or double quotes), single and double quotes no difference
(2) comprising a string of single quotes may be directly enclosed in double quotes, including double quotes string can be used directly in single quotation marks
(3) in the string by double quotes if enclosed in double quotes, a backslash is required, note the "\"; the same string with single quotation marks included in single quotes also need to be escaped
(4) If a backslash use, enter '\\'

Alert ( " Welcome to the blog Park \" Perfect * \ " " );

 

 

 

js Data Type

Numeric types is that you can do mathematical operations (addition, subtraction) data types directly.
Writing directly on it
100 -100
the 100.00 100.3 -90.4
123e5 (12.3 million) 123e5 (0.00123) // scientific notation

alert(100)

 

 

 

 

 

 

All data types in JavaScript
string (string)
number (number)
Boolean (boolean)
array (Array)
objects (object)
empty (null)
undefined (undefined)

 

typeof () determines the type of data, not displayed directly:

eg:

Alert ( typeof ( " Welcome to the garden \\ blog \" Perfect * \ " " ));

effect:

 

 

 

JavaScript statement
to a statement; semicolon

 

Notes:
single-line comments //
Multiline comments / * * /
Shortcuts

 

Declaration of variables js

 

Variables in JavaScript

var x = 2; // variable declaration statement, an assignment statement

x = 3;
variable which is a data storage, using a variable, which is equivalent to using the variable data!

Variables can be reused

Why not just use the data, which is used by variables?

var str = " the Hello World !! " ; // the right assignment left 
        alert (str);

var (variable) is used to define variables;

=: Assignment operator

In some cases, the data we need to store the changes, such as the fraction of time playing games.

 

Note the variable js

(JavaScript is weakly typed language)
when the variable declaration does not need to specify the type of
the variable type is determined by the value of this variable inside the
variable to store different types of data
to declare variables is not necessary (provided that the variable is assigned , or else its result is still undefined)

var Score; // declaration 
        Score = 0 ; // variable when the first assignment is called initialization 
        alert (score);

Variable is declared, but has not been assigned, the result is undefined

 

Multiple variable declarations

var name1 = v1, name2 = v2, v3 = name3;

JavaScript variable naming rules

 

1, the variable must begin with a letter
2, variables can (not recommended) and _ symbols beginning with $
3, variable names are case sensitive (y and Y are different variables)
4, can not use the keyword

 

JavaScript keywords
var break continue function ...

The information is printed on the console:

 

 

console.log(score);

Assignment and arithmetic operators

Operators
assignment operator =
Arithmetic Operators + - * /% + -
assignment operator + = - = = * / =% =
string concatenation
string, and other types of data are added

var A = 100 ; // assign the right to the left of the variable 
        var B = 100 ;
         var C1 = A + B;
         var C2 = A- B;
         var C3 = A * B;
         var C4 = A / B; 
        
        
       the console.log ( C1); 
       the console.log (C2); 
       the console.log (C3); 
       the console.log (C4);

 

Browser printed display:

 

 

 

 

 

 Adding the digital string, numeric string will be converted to splicing:

var D1 = 100 + " Perfect * " ;
        var D2 = " Perfect * " + 100 ;
        var D3 = 100 + 100 + " Perfect * " ;
        var D4 = " Perfect * " + 100 + 100 ;
        var d5 of = "" + 100 + 100 ; // to digital conversion method to a string of 
       the console.log (D1); 
       the console.log (D2); 
       the console.log (D3);
       console.log(d4);
       console.log(d5);
       

Browser console print the results:

 

Guess you like

Origin www.cnblogs.com/jiguiyan/p/11487595.html