JavaScript中的delete,typeof,instanceof运算符

来源:互联网 发布:linux查看日志技巧 编辑:程序博客网 时间:2024/05/16 12:34
  • delete
    运算符删除对以前定义的对象属性或方法的引用。
  • typeof
    返回一个用来表示表达式的数据类型的字符串。typeof 返回值有六种可能: “number,” “string,” “boolean,” “object,” “function,” 和 “undefined.”
  • instanceof
    instanceof 运算符与 typeof 运算符相似,用于识别正在处理的对象的类型。与 typeof 方法不同的是,instanceof 方法要求开发者明确地确认对象为某特定类型。例如:

实例

下面哪些语句可以在JS里判断一个对象oStringObject是否为String。A. oStringObject instanceof StringB. typeof oStringObject == 'string'C. oStringObject is StringD. 以上答案都不正确
var string = "sdagsdf"document.write(typeof string + "<br>");//stringdocument.write((typeof string == "string") + "<br>");//true//document.write(string instanceof string);//出错var s = new String("sdfhnjs");//必须显示的定义类型document.write((s instanceof String) + "<br>");//true
0 0
原创粉丝点击