day10

// const student = {
// ‘studentName’: ‘xiaojichao’,
// age: 49,
// learn() {
// console.log(‘hello, JavaScript!’);
// }
// };

// student[“studentName”]
// student.learn();

// const oStudent = new Object();
// oStudent.studentName = ‘xiao’;
// oStudent.age = ‘50’;
// oStudent.learn = function() {
// console.log(‘hello’);
// };

// delete oStudent.studentName;

// console.log(oStudent.studentName); // undefined

// let studentName = ‘xiaojichao’, age = 49;

// const oStudent1 = {
// studentName: studentName,
// age: age,
// learn() {
// console.log(‘hello, learn me’);
// }
// };

// oStudent1.learn();
// oStudent1’learn’;

// console.log(oStudent1.age);

// const oStudent2 = {studentName, age};

// console.log(oStudent2.studentName);

// let a = ‘catch’, b = ‘Phrase’;
// const hulk = {
// name: ‘Hulk’,
// [a + b]: ‘Hulk Smash!’
// };

// console.log(hulk); // { name: ‘Hulk’, catchPhrase: ‘Hulk Smash!’ }

// const name = Symbol(‘name’);
// const superGirl = {[name]: ‘superGirl’};

// console.log(superGirl[name]); // -> “superGirl”

// const realName = Symbol(‘real name’);
// superGirl[realName] = ‘kara Danvers’; // 添加新属性

// console.log(superGirl[realName]); // -> ‘kara Danvers’
// console.log(superGirl.realName); // undefined

// console.log(superGirl); // -> { [Symbol(name)]: ‘superGirl’, [Symbol(real name)]: ‘kara Danvers’ }

// const daredevil = {
// [name]: ‘Daredevil’,
// [realName]: ‘Matt Murdoch’
// };
// console.log(daredevil); // -> { [Symbol(name)]: ‘Daredevil’, [Symbol(real name)]: ‘Matt Murdoch’ }

const student = {
studentName: ‘xiaojichao’,
age: 49,
learn() {
console.log(‘hello, JavaScript!’);
}
};

console.log(‘studentName’ in student);
console.log(‘learn’ in student);

if (student.studentName !== undefined) {
console.log(‘studentName属性存在!’);
}

if (student.hasOwnProperty(‘learn’)) {
console.log(‘learn方法存在’);
}

for (let p in student) {
console.log§;
}

for (let key of Object.keys(student)) {
console.log(key);
}

for (let value of Object.values(student)) {
console.log(value);
}

for (let [key,value] of Object.entries(student)) {
console.clear();
console.log(key: ${key}, value: ${value});
}

const jla = {
superman: { realName: ‘Clark Kent’ },
batman: { realName: ‘Bruce Wayne’ },
wonderWoman: { realName: ‘Diana Prince’ },
flash: { realName: ‘Barry Allen’ },
aquaman: { realName: ‘Arthur Curry’ },
};

console.log(jla.wonderWoman.realName); // -> Diana Prince

const thor = {
name: ‘Thor’
};
const cloneThor = thor;

cloneThor.name = ‘Clor’;

console.log( thor.name ); // -> ‘Clor’

// 包装器对象

let x = new String(‘xyz’);

console.log(x.length) // 3
console.log(typeof x); // ‘object’
console.log(x.valueOf()); // ‘xyz’
console.log(x.toString()); // ‘xyz’

let b = String(‘123’);
console.log(typeof b);

console.log(‘1’.toString());

// Boolean 对象
// 1.构造函数
let bool = new Boolean(true);

console.log(typeof bool); // ‘object’
console.log(bool.valueOf()); // true

// 2.转换为boolean值
Boolean(undefined); // false
Boolean(null); // false
Boolean(0); // false

let a;
if (Boolean(a)) {
console.log(a);
}

// Number

let c = new Number(123);
console.log(typeof c); // ‘object’

// for (const p in c) {
// console.log§;
// }

Number.isNaN(‘1212s’);

//console.log((345).toLocaleString(‘zh-hans-CN-u-nu-hanidec’));
// Number.toString();

let s1 = ‘xyz’;
let s2 = new String(‘xyz’);
console.log(typeof s1) // ‘string’
console.log(typeof s2) // ‘object’
s2.valueOf() // ‘xyz’
console.log(s2.length); // 3
console.log(s2[1]); // y

const batman = {"name": "Batman", "real name": "Bruce Wayne", "height": 74, "weight": 210, "hero":true, "villain": false, "allies": ["Robin","Batgirl","Superman"] }

let a = JSON.parse(batman);
console.log(a.name);

const oStudent = {
name: ‘xiaojichao’,
age: undefined,
org: [‘lovo’,‘bean’],
company: {cName: ‘lovo’, pos: ‘一环路’},
learn() {
console.log(‘I am learning JavaScript’);
}
};

let b = JSON.stringify(oStudent);
console.log(b);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值