javascript does not support overloaded function or method, it will only cover
function add(number)
{
alert(number + 10);
}
function add(number)
{
alert(number + 20);
}
add(20); // 40
javascript, the function is the object, JavaScript has a built-in Function objects
Because the definition of a relative to add method
var add = new Function("number","alert('hello')");
var add = new Function("number","alert('world')");
So behind the front cover, there is no heavy-duty
javascript is a dynamic language, rather than compiled language, is to interpret the language
NaN not a number
Function arguments has a built-in objects
alert (add.length); / / the length of the desired parameters
Function is the object
JavaScript in the five original value: Undefined, Null, Boolean, Number, String
java 8 basic data types:
byte b; 1 byte
short s; 2 bytes
int i; 4 bytes
long l; 8 bytes
char c; 2-byte (C is a 1-byte languages)
float f; 4 bytes
double d; 8 bytes
boolean bool; false / true
Undefined data type there is only one value: undefined
var s;
alert (s); / / undefined.
Null data type is only one value: null
alert (typeof null); / / object
Boolean data type has only two values: true, false
the return value of typeof five: undefined, boolean, number, string, object
The function, if it does not return value, then its return value for the undefined
function test()
{
alert("");
}
alert(test()); //undefined 没有返回值
alert(test); //打印函数的源代码
var s ; alert(s); //undefined alert(s2); //s2没有定义,报错 var s ; alert(typeof s); //undefined alert(typeof s2); //undefined //null与undefined的关系: undefined实际上从null派生而来 alert(undefined == null)
javascript memory leaks occur, the client memory leak. Therefore, all joined in the function var, textile
Memory Leak
There are three cast: Boolean (value), Number (value), String (value)
Object of the Father of all types of categories
o.name = "langsin";
delete o.name;
js scope (for the definition of the variable function, the increase in local variables var said, not that global var
Variable in the javascript is not block-level scope)
function test()
{
s = "hello";
}
alert(s); //hello
function test()
{
var s = "hello";
}
alert(s); // s没有定义,
//js的作用域
function f(props) {
for(var i=0; i<10; i++) {}
alert(i); //10 虽然i定义在for循环的控制语句中,但在函数
//的其他位置仍旧可以访问该变量.
if(props == "local") {
var sco = "local";
alert(sco);
}
alert(sco); //同样,函数仍可引用if语句内定义的变量
}
f("local"); //10 local local
var sco = "global";
function print1() {
alert(sco); //global
}
function print2() {
var sco = "local";
alert(sco); //local
}
function print3() {
alert(sco); //undefined
var sco = "local";
alert(sco); local
}
print1(); //global
print2(); //local
print3(); //undefined local
The first two functions are very easy to understand, the key is the third: the first statement did not alert to the overall change
Amount of "global" is displayed,
But undefined, this is because in print3 function, we define local variables sco (regardless of location
Where), then the overall
sco attribute will not work in the internal function, so the first alert in the sco is sco local variables, with
When on:
function print3() {
var sco;
alert(sco);
sco = "local";
alert(sco);
}
From this example, we have come, in the definition of local variables inside functions, it is best put in the necessary change at the beginning of
The definition of a good quantity in order to avoid mistakes.
var scope = "global" //定义全局变量
function print() {
alert(scope);
}
function change() {
var scope = "local"; //定义局部变量
print(); //虽然是在change函数的作用域内调用print函数,
//但是print函数执行时仍旧按照它定义时的作用域
起作用
}
change(); //golbal
Comparison of finishing chaos







