Skip to content

Commit 5a5930e

Browse files
committed
update
1 parent 2fad27b commit 5a5930e

8 files changed

+238
-0
lines changed

ES6/01_var_let_const.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// var, let , const
2+
// update, redifine
3+
4+
// menggunakan var tidak masuk akal
5+
// karena dia bisa redifine ulang
6+
var name = 'dncode';
7+
console.log(name); //dncode
8+
name = 'john doe';
9+
console.log(name); //john doe
10+
var name = 'orange';
11+
console.log(name); // orange
12+
13+
// **** let
14+
console.log('**************LET****************');
15+
let names = 'jane';
16+
console.log(names);
17+
names = 'susy';
18+
console.log(names); // susy
19+
// let names = 'orange'; // will error but this make sense!
20+
21+
console.log('**************CONST****************');
22+
const person = 'codeone';
23+
console.log(person); //codeone
24+
// person = 'codetwo'; //will error but this make sense!
25+
const firstName = {
26+
name: 'john doe',
27+
};
28+
29+
console.log(firstName.name);
30+
// redefine again for object its CAN
31+
firstName.name = 'Edward NewGate';
32+
console.log(firstName.name); // Edward NewGate
33+
// add obj
34+
firstName.address = 'Blue Sea';
35+
console.log(firstName);

ES6/02_global_scope.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// global
2+
let names = 'dncode';
3+
let result = 'true';
4+
5+
if (true) {
6+
let names = 'john doe inside if';
7+
console.log(`this is true`);
8+
}
9+
10+
console.log(names);
11+
/* output:
12+
this is true
13+
dncode
14+
15+
if will print for first cz true
16+
and names still dncode because let names on if statement is local variable not global
17+
*/
18+
19+
// example again
20+
{
21+
let shpName = 'mugiawara no lutfy';
22+
console.log(`${shpName} & ${names}`);
23+
}
24+
25+
{
26+
let shpName = 'mugiawara no lutfy';
27+
console.log(`${shpName} & ${names}`);
28+
}
29+
30+
// outpus is: dncode will print cause is global variable
31+
// mugiawara no lutfy & dncode
32+
// mugiawara no lutfy & dncode

ES6/03_template_string.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// template string
2+
3+
let names = 'mugiwara no lutfy';
4+
const member = 'shp';
5+
const yearsAge = 2001;
6+
7+
const printhere = `Hello my name is ${names} and member from ${member.toUpperCase()} and my ages is ${
8+
2020 - yearsAge
9+
}`;
10+
console.log(printhere);
11+
12+
// Hello my name is mugiwara no lutfy and member from SHP and my ages is 19

ES6/04_template_html.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const shpList = {
2+
names: 'lutfy',
3+
pirates: 'shp',
4+
members: ['zoro', 'sanji', 'nami'],
5+
};
6+
7+
const content = document.getElementById('info-content');
8+
9+
// field content use innerHTML
10+
content.innerHTML = `
11+
<p>${shpList.names} ${shpList.pirates.toUpperCase()}</p>
12+
<ul>List member from ${shpList.pirates.toUpperCase()}
13+
${shpList.members
14+
.map((item) => {
15+
return `<li>${item.toUpperCase()}</li>`;
16+
})
17+
.join('')}
18+
</ul>
19+
`;

ES6/05_template_tag.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const content = document.getElementById('content');
2+
3+
const person = {
4+
name: 'john doe',
5+
job: 'developer',
6+
};
7+
8+
const quote = modifedStyle`Hello my name is ${person.name.toUpperCase()} and my job as ${person.job.toUpperCase()} `;
9+
content.innerHTML = quote;
10+
11+
// function modifedStyle
12+
function modifedStyle(text, ...vars) {
13+
// console.log(text, vars);
14+
const awesomeText = text.map((item, index) => {
15+
return `${item} <strong class="blue">${vars[index] || ''}</strong>`;
16+
});
17+
18+
return awesomeText.join('');
19+
}

ES6/06_arrow_functions_basics.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// arrow functions or fat arrow functions
2+
// no name, always expressions, assign to varibles
3+
// not function keyword
4+
// 'this'
5+
6+
// function sayHi() {
7+
// console.log(`Hello World`);
8+
// }
9+
// sayHi();
10+
11+
// const hello = function (name) {
12+
// console.log(`Hello ${name}`);
13+
// };
14+
// hello('john');
15+
16+
// function triple(value1, value2) {
17+
// return value1 * value2 * 3;
18+
// }
19+
20+
const helloMan = () => console.log(`Hello World !`);
21+
helloMan();
22+
23+
// one parameter
24+
const double = (value) => value * 20;
25+
const result = double(20);
26+
console.log(result);
27+
28+
// two parameter
29+
// remember use { return }
30+
const multiple = (num1, num2) => {
31+
const result = num1 * num2;
32+
return result;
33+
};
34+
35+
const sum = multiple(100, 10);
36+
console.log(sum);
37+
38+
// return obj
39+
// disini menggunakan ({obj})
40+
// agar js tidak bingung shingga dibutuhkan ()
41+
const obj = () => ({ name: 'john', age: 25 });
42+
const person = obj();
43+
console.log(person);
44+
45+
// example again use filter
46+
const numbers = [20, 30, 40, 50];
47+
48+
const highNumber = numbers.filter((number, index) => {
49+
console.log(index); //print index 0,1,2,3
50+
return number < 20; // false [] cz small then 20 not there is no
51+
});
52+
console.log(highNumber);
53+
54+
// addEventListener
55+
const btn = document.querySelector('.btn');
56+
57+
btn.addEventListener(
58+
'click',
59+
() => (
60+
(btn.style.background = 'black'), (btn.style.textTransform = 'uppercase')
61+
)
62+
);

ES6/07_arrow_functions_object_this.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Arrow functions or Fat Arrow Functions
2+
// reg function : 'this' refers parent, left of the dot
3+
// arrow function: referes to it's current surrounding scope
4+
5+
const bob = {
6+
firstName: 'bobo',
7+
lastName: 'smith',
8+
sayName: function () {
9+
console.log(this);
10+
setTimeout(() => {
11+
console.log(this);
12+
console.log(`Hello my name is ${this.firstName} ${this.lastName}`);
13+
}, 2000);
14+
},
15+
};
16+
17+
const anna = {
18+
firstName: 'anna',
19+
lastName: 'sanders',
20+
sayName: () => {
21+
console.log(this);
22+
console.log(`Hello my name is ${this.firstName} ${this.lastName}`);
23+
},
24+
};
25+
26+
// invoke
27+
bob.sayName();
28+
// anna.sayName();

ES6/index.html

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Document</title>
7+
<style>
8+
body {
9+
text-transform: capitalize;
10+
display: grid;
11+
place-items: center;
12+
min-height: 100vh;
13+
}
14+
15+
.btn {
16+
background: red;
17+
color: #fff;
18+
border-radius: 0.5rem;
19+
text-transform: capitalize;
20+
cursor: pointer;
21+
font-size: 1.5rem;
22+
padding: 1rem 4rem;
23+
}
24+
</style>
25+
</head>
26+
<body>
27+
<button class="btn">click me</button>
28+
</body>
29+
<!-- <script src="./06_arrow_functions_basics.js"></script> -->
30+
<script src="./07_arrow_functions_object_this.js"></script>
31+
</html>

0 commit comments

Comments
 (0)