DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 967,611 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
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)

Visualizing Promises and Async/Await 🀯

async await

☝️ Check out this all-time classic DEV post