javascript study notes three: javascript basic data types + regular expressions + exception handling

1. Regular expression in javascript: use new RegExp();//var reg = /\\/gm;//match backslash and use regular expression literal; //var reg = new RegExp('\\ \\','gm');Regular expression literal notation uses a slash'/' to wrap the regular expression pattern used for matching. After the second slash, the pattern can be modified to not add The letter form of quotation marks (g--global match; m--multiline match; i--case-sensitive match).

2. The five basic types in javascript: number, character channel, Boolean, null and undefined; in addition to null and undefined, the other three types have basic packaging objects, you can use the built-in constructor Number(), String() , Boolean () to create a packaging object. Basic numbers and digital objects:

var a = 100;//基本数字
  alert(typeof a)//"number"
  var b= new Number(100);
  aelrt(typeof b)//"object"
3. Exceptions in javascript: There are some built-in error constructors in javascript, such as Error()/SyntaxError()/TypeError(); thorw applies to any object, not necessarily an object created by an error constructor. So Ke chooses to throw his own objects, such as:
  try{
	  //进行监控的代码片段
	throw{
		name:"myErrorType",
		message:"oops",
		extra:".........",
		remedy:myErrorHandler//指定应该处理错误的函数
	}
  }catch(e){
	alert(e.message);//oops
	e.remedy();//更优美的处理方式,调用错误处理函数
  }


Guess you like

Origin blog.csdn.net/nanxiaotiantian/article/details/20216655