Home > Web Front-end > JS Tutorial > JavaScript learning

JavaScript learning

高洛峰
Release: 2016-10-15 17:55:24
Original
1208 people have browsed it

title: Javascript
tags: javascript, learning
grammar_cjkRuby: true
---

Define variables

Three forms

var name;
var name = "zhang san";
var name; name = "zhang san";
Copy after login

Data types of Javascript

6 data types

String
Single quotes or double quotes

var name = "zhang san";
var name = 'zhang san';
Copy after login

Number
Calculation, counting

var cost = 8.32;
Copy after login

boolean
The value can only be true or false;

var yes = true; 
var no = false;
Copy after login

Array
An index array is a series of different data items, and the data is accessed through the subscript index array[index];

var array = ['hp','apple','lenovo'];
var apple = array[1];
Copy after login

Object
js object, similar to java class, can have its own attributes; can be accessed through 'object.property';

var stu = {"id":1,"name":"zhang san"};
var name = stu.name;
Copy after login

null
has no value

var a = null;
Copy after login

==Javascript is an implicit language and does not need to specify data Type, the interpreter will automatically analyze the correct data type==
In addition, you can assign one data type to another data type, such as

var id = "测试id"; 
id = 1;
Copy after login

arithmetic operator

JavaScript learning

var a = 9;
var b = a++;
//结果 a=10 b=9
Copy after login

JavaScript learning

var a = 5;
a += 5;
//a = 6
Copy after login

comparison operation Symbol

JavaScript learning

Use of array

Create array

var t1 = ['zhang','li'];
Copy after login
var t2 = new Array();
t2[0] = 'zhang' ;
t2[1] = 'li' ;
Copy after login
var t3 = new Array();
t3.push('zhang');
t3.push('li');
Copy after login

Operation method

JavaScript learning

Use of string

Escape characters

JavaScript learning

Operation string

JavaScript learning

var str = '今天是祖国的67岁生日';
alert(str.substring(3,9));
Copy after login

JavaScript learning

from Define object

var user = new object();
user.name = "zhang";
user.age = 18;
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template