/* untuk menjalankan berkas ini, pastikan pada konfigurasi run setting -> run command
Anda menetapkan nilai "node object.js" */
// inisialisasi objek ke variabel
let object = {key1: "value1", key2: "value2", key3: "value3"}
let user = {
firstName: "Harry",
lastName: "Potter",
age: 20,
isMuggle: false,
stuff: ["Magic Wind", "Flying Car", "Owl"]
};
console.log("Hallo, nama saya " + user.firstName + " " + user.lastName);
console.log("Umur saya " + user.age + " tahun");
/* output
Hallo, nama saya Harry Potter
Umur saya 20 tahun
*/
let user2 = {
name: {
first: "Harry",
last: "Potter"
},
age: 20,
isMuggle: false,
stuff: ["Magic Wind", "Flying Car", "Owl"]
}
console.log("Hallo, nama saya " + user2.name.first + " " + user2.name.last);
/* output
Hallo, nama saya Harry Potter
*/
/* untuk menjalankan berkas ini, pastikan pada konfigurasi run setting -> run command
Anda menetapkan nilai "node arrays.js" */
let myArray = ["Coklat", 42.5, 22, true, "Programming"];
console.log(myArray);
/* output:
[ 'Coklat', 42.5, 22, true, 'Programming' ]
*/
console.log(myArray[1]);
/* output:
42.5
*/
console.log(myArray[0]);
console.log(myArray[1]);
console.log(myArray[2]);
console.log(myArray[3]);
console.log(myArray[4]);
console.log(myArray[5]);
console.log("Panjang nilai myArray adalah " + myArray.length + ".");
/* output:
Coklat
42.5
22
true
Programming
undefined
Panjang nilai myArray adalah 5.
*/