JavaScript Basics (third time)

Source: Internet
Author: User

Variable

Person=null; Empty variables

Carname= "Volvo"; Assign to an undeclared variable, it will become a global variable, even inside the function

Window.carnam; All data variables belong to the Window object

Character accessing a string: Using the location index

var carname = ' Volvo XC60 ';

var character = carname[7];

var y = new String ("John"); Do not use this method to declare variables

Data type

typeof [1,2,3,4]; Return object

typeof null; Return object

typeof new Date (); Return object

typeof new Array (); Return object

typeof NaN; return number

var answer; Console.log (typeof answer); Back to undefined

typeof undefined; Undefined

typeof null; Object

NULL = = undefined//False

NULL = = undefined//True

typeof function () {}//return function

typeof ABC; Back to "undefined"

5 Types of data:

String

Number

Boolean

Object

function

3 Types of objects:

Ojbect

Date

Array

3 types of data that do not contain any values:

Null

Undefined

Number (""); Returns 0

Number (""); Returns 0

Number ("99 88"); Return NaN

JS exception

try{

var X=document.getelementbyid ("Demo"). Value;

if (x== "") throw "empty";

}catch (Err) {

var Y=document.getelementbyid ("mess");

Y.innerhtml= "Error:" + err;

}

Javascript:void (0) means dead link , click No response

JS function

declaration by expression :

var x = function (A, b) {return a*b;}

functions can be called before a declaration : only function mode

MyFunction (5);

function MyFunction (y) {

return y*y;

}

self-calling functions :

(function () {

var x = "Hello";

})();

Functions can be used as a value:

function func (x, y) {

return x*y;

}

var a = func (4,3);

var B = func (4,3) + 5;

Default Parameters :

function myFunction (x, y) {

y = y | | 0;

}

Arguments object:

var x = SumAll (1, 123, 500, 115, 44, 88);

function SumAll () {

var i, sum = 0;
for (i = 0; i < arguments.length; i++) {
Sum + = Arguments[i];
}
return sum;

}

Call/apply: Calling function

function MyFunction (A, b) {

return a * b;

}

Myfunction.call (MyObject, 10, 2);

MyArray = [10,2]; Myfunction.apply (MyObject, MyArray);

;

JavaScript Basics (third time)

Related Article

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.