Appearance
JavaScript Advanced
2
Destructure Object #
js
const info = {
name: 'ls',
desc: 'lists files'
};
const { name } = info;
console.log('name', name);
08.11.2022
JavaScript Advanced
3
Destructure Array #
js
const items = ['apple', 'peach', 'cherry'];
const [ apple, ...rest ] = items;
08.11.2022
JavaScript Advanced
4
Destructure as clone #
js
const info = {
name: 'ls',
desc: 'lists files'
};
const copy = { ...info };
08.11.2022
JavaScript Advanced
5
Short Attributes #
js
const name = 'ls';
const desc = 'lists files';
const command = {
name: name,
desc: desc
};
// kurz
const command = {
name,
desc
}
08.11.2022
JavaScript Advanced
6
Methode, welche eine Object returned #
js
const getCmd = (name) => {
return {
name,
desc: "unspecified"
}
};
// short
const getCmd = (name) => ({
name,
desc: "unspecified"
}
);
08.11.2022
JavaScript Advanced
7
Strictly equals ===
#
js
1 == '1' // true
1 === '1' // false
0 == false // true
0 === false // false
08.11.2022
JavaScript Advanced
8
Entries #
js
const cmd = {
name: 'ls',
desc: 'lists files'
};
for(const [k,v] of Object.entries(cmd)) {
console.log(`${k}: ${v}`);
}
08.11.2022
JavaScript Advanced
9
Nullish ??
#
- returned rechte Seite, falls Ausdruck
null
oderundefined
,0
oder''
.
js
let a = null;
const cmd = a ?? "ls";
let b = "cp";
const cmd1 = b ?? "ls";
08.11.2022