Using JavaScript methods and data structures

  JavaScript is an interpreted programming language that runs in the browser, the Web world, only JavaScript cross-platform, cross-browser web drive, interact with the user.

  1, how to run: Just open a web page, press F12 or find menu -> More Tools -> Developer Tools, developers enter the page click Console (Console)

For example, in the console input: alert ( 'I want to learn JavaScript!');

  Enter the code, press the ENTER key, in which the web page will pop up as a block diagram, the page disappears click OK

  2 comments

Starts with a double slash // until the end of the line is a comment, the comment is posters, and will be ignored by the browser

/ * This is the middle of the comments and will be ignored by the browser * /

  3, the console input: console.log ( 'Hello');

The console will output Hello

The advantage of using console.log () instead of alert () can be avoided annoying pop-up dialog box

   4, JavaScript does not distinguish between integer and floating-point numbers:

123; 123 // integer
0.456; // float 0.456
1.2345e3; // scientific notation 1.2345x1000, equivalent to 1234.5
-99; // negative
NaN; // NaN represents Not a Number, can not be used when the calculation result NaN represents
Infinity; Infinity // represents infinity, the maximum value when the value exceeds the JavaScript Number can be represented, it is expressed as Infinity

It can do four operations directly, and remainder%

  5, the string: "xyz" or 'ABC', note that a portion of "" and '' is not a string of

  6, Boolean values: True, False

&& AND operation, or || operation! Non-operational

For example, in the console run:

var age = 15;
if (age >= 18) {
    alert('adult');
} else {
    alert('teenager');
}

Output:

 Direct pop-up pages teenager

  7, comparison operators:

Input: 2> 5 Output: false

Input: 2 <= 5 Output: true

Input: Output 7 == 7: true

Input: 7 7 === Output: true

== will automatically convert data types and then comparing === does not automatically convert data types in comparison, stick with ===

Input: NaN == NaN output: false

Input: isNaN (NaN) Output: true

Input: 1/3 == (1-2 / 3) Output: false

  8, null and undefined difference:

It represents an empty null value, and '' or '' is not the same, is a numerical value 0 denotes

  9, the array:

①, () creates an array through the Array:new Array(1, 2, 3);

②, use []:var arr = [1, 2, 3.14, 'Hello', null, true];

Input console: var arr = [1,2,3.14, 'Hello', null, true], press enter, input arr [0], output 1, press arr [2], the output 3.14

   10, the object: JavaScript is a group of objects from the key - the value of a set consisting of disordered

var person = {
    name: 'Bob',
    age: 20,
    tags: ['js', 'web', 'mobile'],
    city: 'Beijing',
    hasCar: true,
    zipcode: null
};

Input; PERSON.NAME output '' Bob ''

   11, variable: represented by a variable name, variable names are uppercase and lowercase, numbers, $and _the combination can not start with a number. JavaScript variable names can not be keywords, such as if, whileetc.

var a; // declare a variable, then a value of undefined
var = $ b. 1; // declare variable $ b, $ b at the same time to assign, when a value of $ b. 1
var s_007 = '007 '; // s_007 is a string
var Answer = true; // Answer is a boolean value to true
var t = null; // value of t is null

  12, var: If the variable is not used var, then this variable becomes a global variable

  13, an escape character: \ n newline, \ T denotes a tab character is represented \\ \

How to print: I'm "OK" enter:! I \ 'm \ "OK \"!  

ASCII characters may be represented as \ x ## in hexadecimal form, for example: '\ x41' is equivalent to 'A'

\ U ### represents the unicode characters, for example: '\ u4e2d \ u6587' is equivalent to "Chinese"

  14, multi-line strings: `longitudinal backticks

`I love China 
I love China 
I love China '

  15, the connection string

var name = 'Bob' ;
 var Age = 20 ;
 var the Message = 'Hello,' + name + ', you this year' + age + 'years old!' ; 
Alert (the Message);

 

Guess you like

Origin www.cnblogs.com/Mr-choa/p/12639254.html