#49 What are Pure Functions? | JavaScript Full Tutorial

preview_player
Показать описание
Let's learn about pure functions, first we'll look at a definition and then some examples of pure functions in action.

0:00 - Intro - Like and Subscribe
0:36 - What is a Pure Function?
0:53 - Pure Function example
2:40 - Impure Function example
5:55 - Lesson Summary
6:21- Outro/Up Next

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

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

------------------
Learn with Dev Dreamer! Step by step, easy to understand tutorials :-)
Рекомендации по теме
Комментарии
Автор

It gets me so pumped up every time I recieve a notification from your channel. I thoroughly enjoy your tutorials. I'm in love with the way you explain complex stuff. You're so gifted 😍 You definitely have a knack for it.

SvetaSveta-mshi
Автор

Thank you for making it this clear.A real great video👏

console.log.dev
Автор

Im studying computer science right now and the explanation they gave us i think is easier to understand that what youre trying to explain.

Impure functions are functions that do more than only what they state in their name f.e.

let half = 0;

function sum(a, b) {
half = (a+b) /2
return a+b;
}

As you can see, this 'sum' function is making an addition AND calculating/doing something else that has nothing to do with the name of the function 'sum'.

To make it pure, you need to split the calculation into seperate functions; such as

let half = 0;

function sum(a, b) {
divideBy2(a, b);
return a+b;
}

function divideBy2(a, b) {
half = (a+b)/2;
}

or even cleaner, but now you also change the structure so this might not be what you want since a and b dont need to be equal for both functions
function sum(a, b) {
return a + b;
}

function divideBy2(a, b) {
return (a + b) / 2;
}

let result = sum(4, 6); // 10
let half = divideBy2(4, 6); // 5

jeremygl
Автор

could you create react js step by step tutorials like this? :)

LeonIAm
join shbcf.ru