WorksheetsTest Your JavaScript Fundamental (Part 1)
Total questions: 25
Worksheet time: 4hrs 51mins
let yy = 10;
console.log(++yy);
console.log(yy++);
console.log(yy);
11
12
10
11
12
12
11
12
13
11
11
12
let aa = "10";
console.log(aa++);
console.log(++aa);
console.log(aa);
10
12
12
11
12
10
11
11
10
undefined
let s = [1, 9, 7, 100, 2, 99, 88, 20];
s.splice(2, 4, 91, 92, 93);
console.log(s);
[1, 9, 91, 92, 93, 88, 20]
[1, 91, 92, 93, 99, 88, 20 ]
[1, 9, 7, 20, 91, 92, 93]
[1, 9, 7, 91, 92 , 93, 20]
const arrs = [1, 2, 3];
const { log } = console;
log(arrs.push(4));
[1, 2, 3, 4]
error
4
[1, 2 , 3]
console.log(0.2 + 0.3 === 0.5);
true
false
error
NaN
const arrHewan = ["ayam", `berang"`, "kambing"];
for (let i = 0; i < arrHewan.length; i++) {
console.log(arrHewan[i]);
}
ayam
berang"
kambing
kambing
error
undefined
let multiply = (a, b) => a * b;
let square = (n) => multiply(n, n);
let printSquare = (n) => {
let squared = square(n);
console.log(square(n));
console.log(squared);
};
printSquare(5);
25
25
undefined
25
25
undefined
error
const str = "JavaScript";
const pindah = str;
if (str === "JavaScript") {console.log(pindah, "ini if else");}
else console.log("Salah");
ini if else
JavaScript ini if else
Salah
error
const baru = "new";
const baru = "baru";
console.log(baru);
"baru"
"new"
barunew
error
let arr = [1,2,3,4]
let x = 2 *2;
for (let i = 0; i < 10; i++)
Big O Notation?
O(1)
O(n)
O log n
O (N^2)
let sentence = "hello world";
let words = sentence.split(" ");
console.log(words);
helloworld
[helloworld]
hello world
[ 'hello' , 'world' ]
const date = new Date("2023-11-21");
console.log(Date);
2023-11-21
[Function: Date]
Tue Nov 21 2023 07:00:00 GMT+0700 (GMT+07:00)
error
const falsee = true;
const truee = [];
console.log(typeof falsee);
console.log(typeof truee);
Apakah jenis tipe data yang direturn oleh typeof dalam console log?
string
object
boolean
array
boolean
object
string
array
console.log("1" +1 + 1 + "1");
121
21
31
1111
console.log(1.5 % 0.5);
0
3
0.5
false
const number = 10; //error
console.log(number % 2 == 0 ? "genap" : "ganjil");
error
genap
ganjil
false
let nol = [2, 4, 6, 8, 10];
for (i = 0; i < nol.length; i++)
{console.log(nol[i]);}
error
0
2
4
6
8
2
4
6
8
10
[ ]
let toRupiah = (number) => {
let num = new Intl.NumberFormat("id-ID", {
style: "currency",
currency: "IDR",
});
console.log(num.format(number).replace("IDR", "Rp "));
};
toRupiah(1000);
1000
[Function: toRupiah]
Rp 1.000,00
IDR 1000
const nama = ["Budi", "Agus", "Bambang"];
const HayoApaHayo = nama.map((a) => a + " Doremi");
console.log(HayoApaHayo);
[ 'Budi', 'Agus', 'Bambang']
[ 'Budi', 'Agus', 'Bambang', 'Doremi']
[ 'Budi', 'Agus', 'Bambang', 'a', 'Doremi']
[ 'Budi Doremi', 'Agus Doremi', 'Bambang Doremi' ]
const mobil = {
brand: "BMW",
model: "M4",
price: "$" + 800000,
};
console.log(mobil.model);
BMW
M4
model: M4
[ brand: "BMW", model: "M4", price: "$" + 800000]
const fruit = "mangga";
switch (fruit) {
case "mangga":
console.log("ini mangga");
case "jeruk":
console.log("ini jeruk");
break;
case "salak":
console.log("ini salak");
}
ini mangga
ini mangga
ini jeruk
ini mangga
ini jeruk
ini salak
error
let string = "Hello world";
const search = "ell";
console.log(string.replace(search, ""));
error
[ Hello', 'world']
ell
Ho world
var num1 = 10;
var num2 = 111;
if (num1 > num2) console.log(num1);
else console.log(num2);
10
111
error
infinite loop
let num = 4.01567;
console.log(num.toFixed(2))
4
4.01
4.02
4.0
let arr1 = ["o", "p", "q"];
let arr2 = ["r", "s", "t"];
let split = [...arr2, ...arr1];
console.log(split);
[ ['o', 'p', 'q'], ['r', 's', 't'] ]
[ ['r', 's', 't'], ['o', 'p', 'q'] ]
[ 'o', 'p', 'q', 'r', 's', 't' ]
[ 'r', 's', 't', 'o', 'p', 'q' ]
