indexOf(searchValue[, fromIndex]
可以接受两个参数,第一个为要查询的值,第二个为参数是开始的索引搜索。
索引可以是负数,-1代表最后一个
2. 数组的判断方法 Array.isArray([]); //true
typeof [] === "object" && Object.prototype.toString.call([]) === "[object Array]"
var a; a + 2 //NaN
var n = null; n + 3 //3
var unusualPropertyNames = {
"": "An empty string",
"!": "Bang!"
}
console.log(unusualPropertyNames.""); // SyntaxError: Unexpected string
console.log(unusualPropertyNames[""]); // "An empty string"
console.log(unusualPropertyNames.!); // SyntaxError: Unexpected token !
console.log(unusualPropertyNames["!"]); // "Bang!"
var foo = function bar() {
bar(); //1
foo(); //2
arguments.callee(); //3
};
var a5 = "Cat" && "Dog"; // t && t returns Dog
var a6 = false && "Cat"; // f && t returns false
var a7 = "Cat" && false; // t && f returns false
<a href = "javascript:void(document.forms[0].submit())">click me</a> //提交
var Xmas95 = new Date(1995, 11, 25) //年 月 日
var Xmas95 = new Date(1995, 11, 25, 9, 30, 0); // 年月日 时分秒
function myFunc(theObject) {
theObject.make = "Toyota";
}
var mycar = {make: "Honda", model: "Accord", year: 1998};
var x, y;
x = mycar.make; // "Honda"
myFunc(mycar);
y = mycar.make; // "Toyota"
function myFunc(theObject) {
theObject = {make: "Ford", model: "Focus", year: 2006};
}
var mycar = {make: "Honda", model: "Accord", year: 1998};
var x, y;
x = mycar.make; // "Honda"
myFunc(mycar);
y = mycar.make; // "Honda"
true 从服务器中加载页面,false从缓存中加载页面
12. 将数字转化为2,8,16进制形式的字符串
var num = 16;
num.toString(16) // "f"
parseInt("AF",16) //以16进制转换:175
function doAdd(){
if(arguments.length ==1){
console.log(arguments[0] + 10);
} else if(arguments.length == 2){
console.log(arguments[0] + arguments[1]);
}
}
doAdd(10); //20
doAdd(30,20); //50
window.onerror = function (sMessage, sUrl, sLine)//错误信息,哪个文件,行号
try {
window.nonExistentFunction();
alert("Method completed.");
} catch (exception) { alert("An exception occurred.");
} finally {
alert("End of try卌atch test.");
}
因篇幅问题不能全部显示,请点此查看更多更全内容