属性名和属性值
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var obj=new Object();
obj.name="孙悟空";
obj.var='hello';
console.log(obj.var);
var n="123";
obj["123"]=789;
console.log(obj["123"]);
console.log(obj[n]);
obj.tset=true;
obj.tset=undefined;
obj.tset=null;
console.log(obj.tset);
var obj2=new Object();
obj2.name="盒子";
obj.test=obj2;
console.log(obj.test);
console.log(obj.test.name);
console.log("tset" in obj);
console.log("a" in obj);
</script>
</head>
<body>
</body>
</html>
基本和引用数据类型
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var a=19;
var b=a;
a=10;
console.log(a);
console.log(b);
var obj=new Object();
obj.name="孙悟空";
var obj2=obj;
obj.name="猴子";
console.log(obj.name);
console.log(obj2.name);
var c=10;
var d=10;
console.log(c==d);
var e=new Object();
var f=new Object();
console.log(e==f);
</script>
</head>
<body>
</body>
</html>
对象字面量
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var obj2={};
console.log(typeof obj2);
obj2.name="顺子";
console.log(obj2.name);
var obj3={
name:"八戒",
age:20,
"1234":20,
test:{name:"沙和尚"}
};
console.log(obj3.name);
console.log(obj3.test);
</script>
</head>
<body>
</body>
</html>
函数
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var fun=new Function();
console.log(fun);
console.log(typeof fun);
var fun1=new Function("console.log('Hello 这是我的第一个函数');");
console.log(fun1);
fun1();
function fun2(){
console.log("这是我的第二个函数~~~")
};
console.log(fun2);
fun2();
var a=function(){
console.log("这是函数中的代码");
};
console.log(a);
a();
</script>
</head>
<body>
</body>
</html>
|