Skip to content

Commit 4d4982d

Browse files
committed
complete working with BigInt
1 parent 79b5209 commit 4d4982d

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

11_Working_with_Arrays/script.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ console.log('22' - 0);
481481

482482
// Parsing Integer => Numbers without decimals
483483
console.log(Number.parseInt('50px', 10));
484-
console.log(Number.parseInt('ae34', 10)); // won't work, first value must be a number
484+
console.log(Number.parseInt('ae34', 10)); // won't work, value must start with a number
485485

486486
// Parsing Float => Numbers with decimals
487487
console.log(Number.parseInt('2.5rem')); // Will only return first number
@@ -536,3 +536,57 @@ console.log(Math.floor(-23.9)); // Truncate integers including decimals
536536
console.log((2.7).toFixed(0));
537537
console.log((2.7).toFixed(3));
538538
console.log(+(2.345).toFixed(2));
539+
540+
// 🔸Remainder Operator🔸
541+
console.log(5 % 2);
542+
console.log(5 / 2);
543+
544+
console.log(6 % 2);
545+
console.log(6 % 3);
546+
547+
// checking if a number is even or odd
548+
const checkEvenOdd = num =>
549+
num % 2 === 0 ? console.log(`${num} is even`) : console.log(`${num} is odd`);
550+
checkEvenOdd(22);
551+
checkEvenOdd(16);
552+
checkEvenOdd(3);
553+
554+
labelBalance.addEventListener('click', function () {
555+
[...document.querySelectorAll('.movements__row')].forEach(function (
556+
row,
557+
index
558+
) {
559+
// 0, 2, 4, 6, ...
560+
if (index % 2 === 0) row.style.backgroundColor = 'orangered';
561+
// 0, 3, 6, 9, ...
562+
if (index % 3 === 0) row.style.backgroundColor = 'blue';
563+
});
564+
});
565+
566+
// 🔸Working with BigInt🔸
567+
console.log(2 ** 53 - 1);
568+
console.log(Number.MAX_SAFE_INTEGER);
569+
console.log(2 ** 53 + 2);
570+
571+
console.log(235972592735792702175273597235n); // the n keyword converts numbers >= 2^53 - 1 into BigInt
572+
console.log(BigInt(235972592)); // this conversion only works with smaller BigInt numbers
573+
console.log(BigInt(235972592));
574+
575+
// operations with bigint
576+
console.log(10000 + 10000);
577+
console.log(1000000000000000000000n * 45252332523n);
578+
579+
const huge = 57935737592739325723523n;
580+
const number = 23;
581+
// console.log(huge * number); // can't convert bigint to number
582+
console.log(huge * BigInt(number));
583+
584+
// exceptions
585+
console.log(20n > 15);
586+
console.log(20n === 20);
587+
console.log(typeof 20n);
588+
console.log(20n === '20');
589+
590+
console.log(huge + ' is Really big!');
591+
console.log(11n / 3n);
592+
console.log(12n / 3n);

0 commit comments

Comments
 (0)