forked from uciharis/materi_masEko
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
993 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}/44_this.js" | ||
} | ||
] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// menambah string dg data lain biasa dengan "+" | ||
//kasus tertentu, ribet kalo banyak | ||
//pake fitur string template | ||
//dengan backtick ` beda dengan petik 1 ' | ||
|
||
let nama = "jokodiwowok"; | ||
let tempelete = `nama saya ${nama}`; | ||
console.log(tempelete); | ||
let namaDepan ="muhamad"; | ||
let namaTengah ="suoki"; | ||
let namaBelakang="minamino"; | ||
let namaLengkap = `nama saya : ${namaDepan} ${namaTengah} ${namaBelakang}` | ||
console.log(namaLengkap); | ||
|
||
//string template bisa dikasi operatorlogik | ||
let nilaiKu =95; | ||
let hasilKu = `${namaLengkap} lulus:${nilaiKu>80}`; | ||
console.log(hasilKu); | ||
|
||
//string template bisa string multiline | ||
let konten = `nama saya moeldoko | ||
saya goblok dan pemakan uang rakyat | ||
pilih saya nanti | ||
pas pemilu | ||
terima kasih`; | ||
|
||
console.log(konten); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//misalkan user input string | ||
//tetapi kita perlu mengelola dlm bentuk number | ||
//perlu dikonversi | ||
|
||
let value1="1"; | ||
let value2=1; | ||
let jumlah = value1+value2; | ||
console.log(jumlah); // string ketemu number jd string | ||
|
||
//fungsi konversi | ||
//parseInt() : konversi string ke number bulat | ||
//parseFloat() : konversi string ke number pecahan | ||
//Number() : konversi string ke number pecah/bulat | ||
//number.toString() : konversi number ke string | ||
|
||
let jumlah1=value2+parseInt(value1); //1+parseInt("1") | ||
console.log(jumlah1); | ||
|
||
//NaN : (not a Number) | ||
//terjadi ketika konversi string yang bukan number | ||
let aa="joko"; | ||
let aaa=parseInt(aa); | ||
console.log(aaa); //NaN | ||
//parseInt dan parseFloat bisa mentolerir jika masih | ||
//terdapat number pada variabel | ||
//jika didahului hruf baru angka maka NaN | ||
let bb="12jokodok"; | ||
let cc="j012kodok"; | ||
let bbb=parseInt(bb); | ||
let bbbb=parseFloat(bb); | ||
let ccc=parseFloat(cc); | ||
console.log(bbb); //12jokodok dikonvert jd 12 | ||
console.log(bbbb); //sama dengan parseInt | ||
console.log(ccc); //NaN karena ada string didepan | ||
|
||
//isNaN() : untuk mengecek number atau bukan | ||
//isinya true atau false | ||
|
||
let cekisnan=isNaN(ccc); | ||
console.log(cekisnan); //true karena ccc NaN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//array adalah kumpulan data | ||
//sifat dinamis bs ditambah dikurangi | ||
//berbeda dg java yang panjang array sudah didefinisi | ||
//array seperti laci bs simpan bnyk data | ||
|
||
let arrayKosong = []; | ||
let arrayIsi = ["eko", 30, "laki"]; | ||
console.log(arrayKosong); | ||
console.table(arrayIsi); | ||
|
||
//urutan array dari 0 | ||
//nambah data array ditambahkan ke urutan trakhir | ||
//urutan array disebut index | ||
|
||
//menambah array dengan cara : | ||
//namaArray.push(value) | ||
|
||
let nama =[]; | ||
nama.push("jokowodok"); | ||
nama.push(669); | ||
nama.push("jokriwodok"); | ||
console.table(nama); | ||
|
||
//namaArray.length : panjang array | ||
//namaArray[index] : liat data pada index ke- | ||
//namaArray[index]=value : ubat isi data index ke- | ||
//delete array[index] : hapus data index ke-, index | ||
//tidak geser | ||
|
||
nama[0]="stratos"; | ||
console.table(nama); | ||
delete nama[0]; //index 0 ilang tp urutan tetep | ||
console.table(nama); | ||
console.log(nama.length); //panjang msh 3 meski diapus index 0 | ||
|
||
//data array isinya bebas | ||
//bahkan array bisa masuk ke dalam array | ||
//array dalam array = multidimensi array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//index pada JS array biasa adalah number | ||
//pada PHP index bs berupa string(a.k.a hash | ||
// atau associate array) | ||
//jika kita memaksa bukan number pada indeks array JS | ||
//JS akan merubahnya jd objek, ini justru bahaya | ||
//di python ini adalah dictionary | ||
|
||
//tipe data objek mirip dg array | ||
//indeks pada objek bisa string atau number | ||
//sebutan indeks pada objek dsebut propertis/atribut | ||
//array pake [] | ||
//objek pake {} | ||
|
||
let person ={}; | ||
// operasi mirip di array | ||
//properti/ index pake string | ||
person["nama"] = "eko kurniawan"; | ||
person["alamat"] = "Indonesia"; | ||
person["umur"] = "30"; | ||
console.table(person); | ||
//atau cara deklar objek | ||
let orang = {nama:"jokorowo", alamat:"brazil", umur:30} | ||
console.table(orang); | ||
console.log(orang); | ||
//mengambil properti tertentu | ||
console.log(`nama: ${orang.nama} alamat: ${orang.alamat}`); | ||
//atau | ||
console.log(`nama: ${orang["nama"]} alamat: ${orang["alamat"]}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//if expression | ||
//eksekusi kode tertentu dalam kondisi terpenuhi | ||
//bentuk dasar if | ||
// if(argumen) {output} | ||
//contoh : | ||
|
||
let examValue = 90; | ||
if(examValue>=80){ | ||
console.log("selamat km lulus") | ||
} | ||
|
||
//else expression | ||
//tereksekusi jika kondisi tidak terpenuhi | ||
//bentuk dasar if else | ||
// if(){}else {} | ||
|
||
examValue = 70; | ||
if(examValue>=80){ | ||
console.log("selamat km lulus") | ||
} else { | ||
console.log("mampuss hehe") | ||
} | ||
|
||
//else if expression | ||
//kondisi lebih dari 2 | ||
|
||
examValue =40; | ||
if(examValue>80){ | ||
console.log("anak pintar") | ||
} else if (examValue >60){ | ||
console.log("pemalas") | ||
} else { | ||
console.log("anak goblokkk") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//JS punya fitur sbb: | ||
//fitur ini hanya berjalann di browser not node.js | ||
//a. alert, b. prompt, c. confirm | ||
//alert digunakan memberi peringatan berupa popup text | ||
//prompt digunakan utk meminta input string | ||
//confirm digunakan untuk minta input boolean dr browser user | ||
//---------- contoh prompt --------- | ||
let nama =prompt("isikan namamu"); | ||
alert(`heloo ${nama}`); //run only at browser not in node | ||
|
||
//--------------contoh confirm -------------- | ||
const masuk=confirm("yakin melanjutkan?"); | ||
if(masuk){ | ||
const namaa=prompt("siapa nama mu?"); | ||
alert(`halo ${namaa}`); | ||
} else { | ||
alert("byee"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//salah satu kata kunci di JS | ||
//tidak bs bikin variabel dg nama undefined | ||
//undefined adalah sbuah tipe data | ||
//undefined adalah kondisi variabel yang blm diberi nilai | ||
//undefine tidak sama dengan null | ||
|
||
//undefined variabel | ||
let nama ; //sama dengan nama=undefined | ||
if (nama=== undefined){ | ||
console.log("undefined"); | ||
} else { | ||
console.log("defined"); | ||
} | ||
//undefined array | ||
const namas = ["ko", "nu"]; | ||
if(namas[2]===undefined){ //indeks 2 tidak ada nilai | ||
console.log("array undefined"); | ||
}else { | ||
console.log("array defined"); | ||
} | ||
|
||
//undefined object | ||
const person={name:"muldoko", jk:"laki"};//properti name ada | ||
if(person.name===undefined){ | ||
console.log("object undefined"); | ||
} else{ | ||
console.log("object defined"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//null merupakan data kosong | ||
//null tidak sama dengan undefined. | ||
//null variablenya ada value, value nya null | ||
//undefined variabelnya blm ditambahkan value | ||
|
||
let firstName //= null; | ||
if(firstName===undefined){ | ||
console.log("ini undefined"); | ||
} else if(firstName===null) { | ||
console.log("ini null"); | ||
} else { | ||
console.log(`helo ${firstName}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//switch adalah statement percabangan yang sama dg if | ||
//namun lbh sederhana | ||
//kondisi switch hanya utk perbandingan == | ||
//else pada switch adalah default | ||
|
||
const nilai="G"; | ||
switch (nilai) { | ||
case "A": | ||
console.log("Anda lulus"); | ||
break; | ||
case "B": | ||
case "C": | ||
console.log("Anda lulus"); | ||
break; | ||
case "D": | ||
console.log("Anda tidak lulus"); | ||
break; | ||
default: | ||
console.log("goblok sekali anda") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//operator typeof digunakan utk melihat tipe data suatu variabel | ||
//karna js ini dinamik, kita perlu mengecek tipe datanya | ||
|
||
//tipe---------- hasil typeof | ||
|
||
//undefined------ "undefined" | ||
//null------ "object" | ||
//boolean------ "boolean" | ||
//number------ "number" | ||
//BigInt------ "bigint" | ||
//String------ "string" | ||
//Symbol------ "symbol" | ||
//Function------ "function" | ||
//lainnya------ "object" | ||
|
||
let data; //undefined | ||
const typeData= typeof data; | ||
console.log(typeData); | ||
|
||
let data21={}; //object | ||
const typeData21=typeof(data21); | ||
console.log(typeData21); | ||
|
||
let data31=[]; //object | ||
const typeData31=typeof(data31); | ||
console.log(typeData31); | ||
|
||
let data1="eko"; //string | ||
const typeData1= typeof data1; | ||
console.log(typeData1); | ||
|
||
let data2=123; //number | ||
const typeData2=typeof(data2); | ||
console.log(typeData2); | ||
|
||
let data3=20e10; //number | ||
const typeData3=typeof(data3); | ||
console.log(typeData3); | ||
|
||
let data4=true; //boolean | ||
const typeData4=typeof(data4); | ||
console.log(typeData4); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//pengecekan properti(indeks dalam objek) didalam objek | ||
//jika ada maka true | ||
//selain object, array juga bisa dicek indeksny | ||
//hanya cek ada atau tidak, bukan cek value nya | ||
//meskipun properti atau indeks undefined atau null | ||
|
||
const person = { | ||
firstName:"Eko", lastName:"Khaedy" | ||
} | ||
const hasil ="firstName" in person;//true | ||
console.log(hasil); | ||
|
||
const nama= [null,"kurni",null]; | ||
const hasil1= 0 in nama;//true karna hanya cek indeks 0 meskipun value=null | ||
console.log(hasil); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//ternary operator adalah operator sederhana dr if statement | ||
//ternary operator terdiri dr : kondisi yg dieval; jika true akan ambil nilai pertama; | ||
//jika false maka ambil nilai kedua | ||
|
||
//perbandingan if else dan ternary | ||
//1. if else statemen | ||
const nilai= 78; | ||
if (nilai>=75) { | ||
console.log("selamat anda lulus"); //78>=75 | ||
} else { | ||
console.log("kurang pinter antum"); | ||
} | ||
|
||
//2.ternary statement | ||
const score=75; | ||
const ucapan=score>=75 ? "selamat anda lulus" : "kurang pinter antum"; | ||
console.log(ucapan); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//nullish coalescing operator | ||
//nullish value adalah null dan undefined | ||
//nullish operator (??) adalah operator yang mirip dg ternary, | ||
//yang membedakan adalah pada kondisi, | ||
//jika bernilai null/ undefined, maka value default diambil | ||
//menghindari adanya isian null / undefined, maka diganti nilai lain (default) | ||
|
||
// dengan if | ||
let paramet=null; | ||
if (paramet=== undefined || paramet==null) {// atau (||) | ||
paramet="1. data bernilai undefined atau null" ; | ||
} | ||
console.log(paramet); | ||
|
||
//dengan nullish coalescing | ||
let a; | ||
let cekparam = a ?? "2. data bernilai undefined atau null"; | ||
console.log(cekparam); |
Oops, something went wrong.