Social Share

Hints and Tips on Learning Javascript

Here are some Javascript hints/tips that i have come across when learning to program Javascript and i thought to share them with you.

Small little javascript snippets that will enhance your big Javascript applications as a Javascript programmer.

Javascript Code example 1)...

Check if a string is uppercase

const isUpperCase = str => str === str.toUpperCase();

console.log(isUppercase("string")); //false

console.log(isUppercase("STRING")); //true

console.log(isUppercase("5TR1NG")); //true

Javascript code processing as zeros and zero

Javascript Code example 2)...

Finds the differences between arrays

const differenceInArrays = (array1, array2) => {

    const set = new Set(array2);

    return array1.filter(x => !set.has(x));

};

differenceInArrays(["apple", "orange", "grape"], ["apple", "orange", "pear"]);

// ["grape"]

differenceInArrays([8, 13, 7],[ 25, 8, 9]);

// [13, 7]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Javascript code processing as zeros and zero

Javascript Code example 3)...

Scrolls to the top of the page

const scrollToTopOfPage = ( ) => {

    const c = document.documentElement.scrollTop | | document.body.scrollTop;

    if (c > 0 {

        window.requestAnimationFrame(scrollToTop);

        window.scrollTop(0, c - c / 8);

    }

};

scrollToTopOfPage();