DEV Community

Cover image for JavaScript Built-in Functions
Patricia C.
Patricia C.

Posted on • Updated on

JavaScript Built-in Functions

In the past few months, I've been learning the ropes of JavaScript and came across some useful built-in functions that always come in handy.

Arrow Functions

With arrow functions you don’t need to pass the function keyword; it can also be passed as an anonymous function.

functionOne = ( ) => {
     return console.log(this is an anonymous function);
}

functionTwo  =  parameter => {
    return console.log(this has one parameter);
}
Enter fullscreen mode Exit fullscreen mode

An Inline function doesn’t need the return keyword and you can remove the parenthesis if you’re passing 1 parameter.

const multiply = num => num * 4;

verses

const multiply = (num) => {
return num * 4;
}

Splice

The Splice function selects element(s) in array that can be replaced or removed.

Let fruits = [apple, kiwi, orange, avocado];`

Fruits.splice(2, 0, ‘raspberries’);
Enter fullscreen mode Exit fullscreen mode

2 is where the new element will be positioned, 0 is the number of elements that are removed, ‘raspberry is the new element that's added to the array.

modified array: = [‘apple’, ‘kiwi’, ‘orange’, ‘raspberry’, ‘avocado’];

Slice

Slice Returns a new array.

names = [Pat, John, Ann, Lukas, Tom]
names.slice(2, 3);
new array name: [Ann]
Enter fullscreen mode Exit fullscreen mode

Photo credit: Christina Morillo from Pexels

Top comments (0)