JavaScript Learning Notes

Source: Internet
Author: User
Tags tag name

The 1.javascript engine works by parsing the code, getting all the declared variables, and then running on one line, which results in the declaration of all variables being promoted to the head of the code, which is called the elevation of the variable, and note that the variable promotion is only valid for variables declared by the var command. If a variable is not declared with VAR, the variable promotion will not occur.

2.javascript Label: label is equivalent to a locator, to jump to any location of the program, the format of the label is as follows:

Label

Statement

The function of a label looks at two examples:

Top:For(VarI=0;I<3;I++){For(VarJ=0;J<3j++) {if  (i Span class= "o" >=== 1 && j === 1) break topconsole. Log ( ' i= ' + i +  ', j= ' + j); } }//i=0, J=0//i=0, J=1//I=0, J =2//I=1, j=0             

The above code is a double loop block, the break command is followed by a top label (note, top without quotation marks), meet the conditions, directly jump out of the double loop. If you break do not use a label after the statement, you can only jump out of the inner loop and into the next outer loop.

continueStatements can also be used in conjunction with tags.

Top:For(VarI=0;I<3;I++){For(VarJ=0;J<3;J++) {if  (i === 1 Span class= "o" >&& j === 1) continue topconsole. Log ( ' i= ' + i +  ', j= ' + j); } }//i=0, J=0//i=0, J=1//I=0, J =2//I=1, J=0//i=2, J=0//i=2, J=1//i=2, j=2   

In the above code, continue there is a tag name at the back of the command, and when the condition is met, the current loop is skipped and goes directly to the next outer loop. If you continue do not use labels after the statement, you can only enter the next round of inner loops.

The 3.typeof operator can return the data type of a value

typeof 123 // "number"typeof ‘123‘ // "string"typeof false // "boolean"
typeof undefined // "undefined"
利用这一点,typeof可以用来检查一个没有声明的变量,而不报错。
v// ReferenceError: v is not definedtypeof v// "undefined"

In the above code, the variable v is not var declared with the command, and the direct use will be an error. However, put in the typeof back, will not error, but return undefined .

In practical programming, this feature is usually used in judgment statements.

// 错误的写法if (v) { // ...}// ReferenceError: v is not defined// 正确的写法if (typeof v === "undefined") { // ...}
4.null和undefined
Number(null) // 05 + null // 5


Number(undefined) // NaN5 + undefined // NaN

4.NaN是javascript的特殊值,表示“非数字”,主要出现在将字符串解析成数字出错的场合;
5.Infinity表示无穷,用来表示的两种场景,一种是一个正的数值太大,或一个负的数值太小,无法表示;另一种是非0数值除以0,得到Infinity
6.

If the long string must be divided into multiple lines, you can use a backslash at the end of each line.

var longString = "Long long long string";longString// "Long long long string"























javascript方法汇总:
1)与数值相关的全局方法:
1.1parseInt方法用于将字符串转为整数:parseInt(‘123’) //123 如果parseInt的参数不是字符串,则会先转为字符串再转换
parseInt(1.23) // 1// 等同于parseInt(‘1.23‘) // 1


When a string is converted to an integer, it is a single character, and if it encounters a character that cannot be converted to a number, it will no longer proceed, returning the part that has been transformed.

parseInt(‘8a‘) // 8parseInt(‘12**‘) // 12parseInt(‘12.34‘) // 12parseInt(‘15e2‘) // 15parseInt(‘15px‘) // 15

The arguments in the above code are parseInt all strings, and the result only returns the part of the string that can be converted to a number.

Returns if the first character of a string cannot be converted to a number (except for the sign followed by a number) NaN .

parseInt(‘abc‘) // NaNparseInt(‘.3‘) // NaNparseInt(‘‘) // NaNparseInt(‘+‘) // NaNparseInt(‘+1‘) // 1
1.2  parseFloat()用于将一个字符串转为浮点数

JavaScript Learning Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.