Front-end--3, JavaScript

Source: Internet
Author: User

    • Introduction Method:
      • Write directly in HTML (learn)
      • Write to the file to introduce
    • declaring variables
      • How to assign variable values
      • Assigning a single variable to a value
      • Variable assignment of multivariate variables
    • Data type
      • Number and string
      • Boolean
      • Undefined
      • Storage of data types
      • Array
      • Object
    • How JS is interpreted
    • Operator
    • string concatenation with the + sign
    • NaN
    • Process Control Statements
      • If-else If-else
      • Cycle
    • Function
    • anonymous functions
    • Bom
      • Alter (info)
      • Confirm (Info)
      • Prompt ()

Introduction Method:

There is no requirement to force indentation in any language other than Python. That is, JS does not require indentation, as long as the syntax can be.
The alter in the example is a bullet box

#单行注释//  #多行注释/* 注释*/
Write directly in HTML (learn)
<script>    //第一行JS alter(123)</script>
Write to the file to introduce
<script src="demo.js" ></script>
Declaring variable variables to be assigned a value method

The Var keyword declares that a string is a variable.
Assign a value to the defined variable.

Assigning a single variable to a value
<script>var name;name="yudong"</script>#可以简写为:var age=3;
Variable assignment of multivariate variables

The default is to use a newline character as the statement delimiter. You can also use semicolons as a delimiter for statements

var name="heling"; var age=18
Data type

Print to the screen terminal.

Number and string
// console.log 输出打印到屏幕终端// typeof 查看数据的数据类型i=1f=1.1s="study"console.log(i,typeof i);//numberconsole.log(f,typeof f);//numberconsole.log(s,typeof s);//string//不区分数字和浮点型
Boolean
有两个值,true、false。逻辑判断可以理解为数字类型的。True、False为0,1。可用于数字运算
Undefined

There is only one value, undefined

Two scenarios in which this value is encountered

    • The variable is declared only and is not assigned a value.
    • When a function does not return a value.
Storage of data types

The reference data types all exist in the heap. The underlying data types are stored in the stack.
The heap is stored in the memory address of the stack.

Array

You can deposit multiple data into it.
Languages such as C declare the stored data type when declaring an array

How to create1:var arrname = [Elements0,Elements1,....];var arr=[1,2,3];How to create2:var arrname =NewArray (Elements0, element 1, ...); //var test=new Array ("A", true);  How to create 3:var Arrname = new array ( length); // Initialize Array object: var cnweek= New array (7); Cnweek[0]="  Sunday "Cnweek[1]= 6]= " Saturday";     
Object

The data structure of the mapping relationship. Key Plus no quotation marks can

var obj = {"Q":"Z"}

The basic operation of the dictionary can be used, such as the value:obj["Q" of the key)

Both the array and the object's data type are object.

How JS is interpreted

JS reads the entire file before it starts executing. So the use of variables can be written on top of the variable declaration.

Operator
#++ --var i = 1;i++console.log(i)#==console.log(2=="2")//返回时true,他在有一端是数字时另一端也会转换成数字> #===//不会转换数据类型,数据类型也必须一样。#逻辑运算符,与 或 非&& || !真真为真,假假为假
string concatenation with the + sign Nan

When you convert a data type (the string is converted to a numeric type) it fails to get the type.

Process Control Statements
    • Branch Control Statement if
    • Loop control statement for while

Use {} in JavaScript to confirm the statement block (the body of the statement that executes when the condition is met). In Python, you use: and indent.

If-else If-else
if (表达式1) {    语句1;}else if (表达式2){ 语句2;}else if (表达式3){ 语句3;} else{ 语句4;}
Cycle
    • Traverse Loop for
    • Conditional loops are all conditional loops in the while JavaScript. Exit if the condition is not satisfied

See the picture in detail.

Support for break and continue

The sequence type in JS can be obtained by using. length

Function
function funcname(参数) {    return X;}

A call can pass in any number of arguments, and it only accepts a fixed number.
Accept any length of.
Arguments through an array to get all the arguments passed in

anonymous functions
// 匿名函数    var func = function(arg){ return "tony"; }// 匿名函数的应用 (function(){ alert("tony"); } )() (function(arg){ console.log(arg); })(‘123‘)
BOM

Window is a global variable that can be called without the window name, and alter is the method inside it.

Alter (info)

Used for warning messages, only determined

Confirm (Info)

Displays a dialog box with a message and a confirmation button and a Cancel button. has a return value

Prompt ()

Displays a dialog box to prompt the user for input. has a return value

Each label is an object

Front-end--3, JavaScript

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.