Sintaks untuk menetapkan nilai parameter default untuk suatu fungsi adalah: function functionName(param1=default1, param2=default2, …) { // function body } Contoh 1: Tetapkan Nilai Parameter Default Untuk Fungsi // program to set default parameter value function sum(x = 3, y = 5) { // return sum return x + y; } console.log(sum(5, 15)); console.log(sum(7)); console.log(sum()); Keluaran […]
Tag Archives: Nilai
Sintaks untuk menetapkan nilai parameter default untuk suatu fungsi adalah: function functionName(param1=default1, param2=default2, …) { // function body } Contoh 1: Tetapkan Nilai Parameter Default Untuk Fungsi // program to set default parameter value function sum(x = 3, y = 5) { // return sum return x + y; } console.log(sum(5, 15)); console.log(sum(7)); console.log(sum()); Keluaran […]
Contoh 1: Ekstrak Nilai Menggunakan map() // program to extract value as an array from an array of objects function extractValue(arr, prop) { // extract value from property let extractedValue = arr.map(item => item[prop]); return extractedValue; } const objArray = [{a: 1, b: 2}, {a: 4, b: 5}, {a: 8, b: 9}]; // passing an […]
Contoh 1: Urutkan Array berdasarkan Nama Properti // program to sort array by property name function compareName(a, b) { // converting to uppercase to have case-insensitive comparison const name1 = a.name.toUpperCase(); const name2 = b.name.toUpperCase(); let comparison = 0; if (name1 > name2) { comparison = 1; } else if (name1 < name2) { comparison […]
Contoh 1: Periksa Array Menggunakan include() // program to check if an array contains a specified value const array = [‘you’, ‘will’, ‘learn’, ‘javascript’]; const hasValue = array.includes(‘javascript’); // check the condition if(hasValue) { console.log(‘Array contains a value.’); } else { console.log(‘Array does not contain a value.’); } Keluaran Array contains a value. Pada program […]
Contoh: Bandingkan Nilai Dua Tanggal // program to compare value of two dates // create two dates const d1 = new Date(); const d2 = new Date(); // comparisons const compare1 = d1 < d2; console.log(compare1); const compare2 = d1 > d2; console.log(compare2); const compare3 = d1 <= d2; console.log(compare3); const compare4 = d1 >= […]
ASCII berdiri untuk Kode Standar Amerika untuk Pertukaran Informasi. ASCII adalah nilai numerik yang diberikan ke berbagai karakter dan simbol untuk disimpan dan dimanipulasi oleh komputer. Misalnya, nilai ASCII surat itu ‘SEBUAH’ aku s 65. Sumber: Bagan ASCII dari semua 127 karakter dalam JavaScript. Contoh 1: Nilai ASCII dari Karakter Menggunakan charCodeAt () // program […]
Dari waktu ke waktu, karena berbagai faktor eksternal, nilai mata uang fiat naik atau turun. Meskipun beberapa alasan di balik volatilitas harga mereka eksklusif untuk pasar cryptocurrency, sebagai penyimpan nilai, cryptocurrency tidak terkecuali untuk fluktuasi harga. Faktor penilaian sangat banyak, mulai dari kelangkaan koin, permintaan pengguna, utilitas, dll. Ditambah lagi, sebagian besar aset ini diluncurkan […]
Variabel karakter menyimpan nilai ASCII (angka integer antara 0 dan 127) daripada karakter itu sendiri dalam pemrograman C. Nilai itu dikenal sebagai nilai ASCII. Sebagai contoh, Nilai ASCII ‘A’ adalah 65. Artinya, jika Anda menetapkan ‘A’ ke variabel karakter, 65 disimpan dalam variabel itu daripada ‘A’ itu sendiri. Sumber: bagan ASCII dari 127 karakter dalam […]