Operation With Dates
const calcDaysPassed = (date1, date2) => Math.abs(date2 - date1) / (1000 * 60 * 60 * 24); const calc1 = calcDaysPassed(new Date(2021,10,11),new Date(2021,10,19)); console.log(calc1); => 7
const calcDaysPassed = (date1, date2) => Math.abs(date2 - date1) / (1000 * 60 * 60 * 24); const calc1 = calcDaysPassed(new Date(2021,10,11),new Date(2021,10,19)); console.log(calc1); => 7
1. const new = new Date(); console.log(now); => current time; 2. console.log(new Date('December 24, 2015')); => Thu Dec 24 2015 00:00:00 GMT+0000 3. console.log(new Date(2031,10,11,12,12,10)); 4. console.log(new Date(0)); => Thu…
console.log(Number.MAX_SAFE_INTEGER); => 9007199254740991 //When facing large numbers that are bigger than above number, Js runs into some problems. How to solve? Using BigInt console.log(BigInt(124623786189682165785218589)); => 124623786189682165785218589n //Or console.log(124623786189682165785218589n); => 124623786189682165785218589n…
console.log(Math.sqrt(25)); => 5 console.log(25 ** (1/2)); => 5 console.log(8 ** (1/3)); => 2 console.log(Math.max(5,18,23,11,2)); => 23 console.log(Math.min(5,18,23,11,2)); => 2 //Make a function that can generate random number between min &…
//Lectures How JS Represents Number console.log(23 === 23.000) => true console.log(0.1+0.2) => 0.3000000004 //Turn String into Number console.log(+'23'); => Just Add Plus Symbol //Parsing *take out the number from string…
<script> const checkDogs = function(arr1, arr2){ const arr1Shallow = arr1.slice(); arr1Shallow.splice(0,1); arr1Shallow.splice(-2); const dogs = arr1Shallow.concat(arr2); dogs.forEach(function(age, i){ const type = age >= 3 ? `Dog number ${i+1} is an…
<script> const dogs = [ {weight: 22, curFood: 250, owners: ['Alice', 'Bob']}, {weight: 8, curFood: 200, owners: ['Matilda']}, {weight: 13, curFood: 275, owners: ['Sarah','John']}, {weight: 32, curFood: 340, owners: ['Michael']}…
<script> //filter(current, index, array) const movements = [200, 450, -400, 3000, -650, -130, 70, 5000]; const deposits = movements.filter((mov) => mov > 0); //arrow method function console.log(deposits); const withdraw =…
const secureBooking = function () { let passengerCount = 0; return function () { passengerCount++; console.log(`${passengerCount} passengers`); }; }; const booker = secureBooking(); booker(); booker(); booker(); console.dir(booker); /////////////////////////////////////// // More…
const runOnce = function () { console.log('This will never run again'); }; runOnce(); // IIFE (function () { console.log('This will never run again'); const isPrivate = 23; })(); // console.log(isPrivate);…