JavaScript Pure Functions - Tutorial for beginners

Ғылым және технология

Pure Functions are an essential ingredient of functional programming, regardless of the language. In this video we cover the two major rules that make any function pure, benefits of pure function, as well as why some functions can't be pure. Let's have some fun yo!
This is episode 16 of 20 things Javascript Developers Should Know But Probably Don't.
00:00:00 Intro
00:01:15 What is a pure function?
00:01:52 Rule #1: Same input means same output
00:02:58 🔴 Live coding: Rule #1
00:08:37 Benefits of Rule #1
00:10:04 Testability
00:12:05 Rule #2: No side-effects
00:12:22 🔴 Live coding: Rule #2
00:15:07 Benefits of Rule #2
00:16:40 Impure functions 😱
00:18:17 Outro
ColorCode Etsy Merchandise store:
www.etsy.com/shop/ColorCodeStore
Full playlist here: • 20 Things JavaScript D...
JavaScript Promises from the series "20 Things JS Developers Should Know but Probably Don't"
by ColorCode.io, Sina Jazayeri
** Announcement **
Full JavaScript Mastery course is coming! Sign up for Early Access here:
www.colorcode.io/js-mastery

Пікірлер: 143

  • @ColorCodeio
    @ColorCodeio3 ай бұрын

    Episode 16: Pure Functions 🤘👨‍💻🔥🎉

  • @sergiu6650

    @sergiu6650

    3 ай бұрын

    Well done .. Craig!, Can you post more often ? :D Maybe some React stuff ?

  • @zero11010
    @zero110103 ай бұрын

    The song: counting bodies like sheep to the rhythm of the wardrums Performed by: a perfect circle I love your music references. 👍

  • @ColorCodeio

    @ColorCodeio

    3 ай бұрын

    Correct! Nice job

  • @javeedakhter324
    @javeedakhter3243 ай бұрын

    Javascript legend 🎉👍

  • @mohammadabbas1623
    @mohammadabbas16233 ай бұрын

    Oh man, we need a video editing tutorial as well 😛🤩

  • @MeetPatel_01
    @MeetPatel_01Ай бұрын

    i been browsing advanced Js tutorials all around, i got few but sounds boring, i really appreciate the energy you got while explain things, totally love it, can't wait for more content.

  • @ColorCodeio

    @ColorCodeio

    22 күн бұрын

    I appreciate that!

  • @ALENonEIC
    @ALENonEIC3 ай бұрын

    Honey, wake up. ColorCode posted a new JavaScript video.

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    haha ♥

  • @beinyourguard
    @beinyourguard3 ай бұрын

    Sina I LOVE your way of teaching, it's just so simple, entertaining and helpful

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Thank you!

  • @mikeJohnson2222
    @mikeJohnson22223 ай бұрын

    Bro thanks... The way you break down the entire language is awesome.

  • @4rmboy666
    @4rmboy6663 ай бұрын

    You know you have the perfect combo. The videos are both interesting and useful.

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    I appreciate that!

  • @JohnnyDiabetes
    @JohnnyDiabetesАй бұрын

    ...when you find out your nascent skillset/hobby comes with a KZreadr that makes incredible content with clarity, humor, style, and beauty. And you just wish you could make him understand how much you appreciate him... Thank you, Sina. You're like that indie film that is so special that you want everyone to see it and love it as much as you do. You're my developer-resource version of 'Sing Street' (2016). Or maybe 'You Can Count On Me' (2000). [digital gratitude hug]

  • @sugarfairy1248
    @sugarfairy1248Ай бұрын

    Love your style of video editing and how you present the concepts in such a fun way! You deserve much much more subscribers!

  • @nirau
    @nirau2 ай бұрын

    So happy to found your channel, it makes my frontend developer study journey so much better! Cheers

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Cheers!

  • @Tarek_Abdelhafez
    @Tarek_Abdelhafez3 ай бұрын

    Welcome back with long waiting videos. Please continue. 😀

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Will do!

  • @opsingh861
    @opsingh86118 күн бұрын

    Intro and editing was on the next level 💥💥💥💥

  • @amsxiety
    @amsxiety3 ай бұрын

    Best conceptual coding videos ❤

  • @ColorCodeio

    @ColorCodeio

    3 ай бұрын

    🕺🏻

  • @kiranshelar2961
    @kiranshelar2961Ай бұрын

    Best content for understanding difficullt javascript concepts! Thankyou

  • @hessamt800
    @hessamt8003 ай бұрын

    Hats off to you, nice to have you back.

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

  • @jonathanserwano9948
    @jonathanserwano9948Ай бұрын

    man you are the best at acting and explaining complex stuff for me, i really enjoy your videos

  • @ColorCodeio

    @ColorCodeio

    22 күн бұрын

    Glad you like them!

  • @franexmo81-
    @franexmo81-3 ай бұрын

    Brief, simple, clear and fun. Thanks for this amazing learning material

  • @ColorCodeio

    @ColorCodeio

    3 ай бұрын

    🤘🏼👍🏼

  • @Thassalocracy
    @Thassalocracy3 ай бұрын

    This video should be a preparatory course for React beginners 😏

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    I agree

  • @chhavimanichoubey9437
    @chhavimanichoubey94373 ай бұрын

    My favourite online coding teacher is back

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    ♥🙏

  • @user-kn4oi9oh4i
    @user-kn4oi9oh4i2 ай бұрын

    Best. Intro. Ever. ❤

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    🎉

  • @BigBabyofTel
    @BigBabyofTel3 ай бұрын

    Your style of teaching is effective. I hope you get the energy to do something similar with Typescript. This series on JS is already one of the best ones on YT

  • @ColorCodeio

    @ColorCodeio

    3 ай бұрын

    Great suggestion!

  • @hollam224
    @hollam224Ай бұрын

    Love you soo much your tutorials are first class

  • @tonyhomfray
    @tonyhomfray2 ай бұрын

    You’ve explained pure functions in a way that I finally understand! 🎉 Thank you! 🙏🏼 Loving this whole series ❤ I found it searching for the Fetch API and have been back to watch the whole series 👌🏻

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Awesome. Thanks!

  • @kbkmn
    @kbkmn3 ай бұрын

    great video as always. i think that you should address that functional programming is often about higher order functions and state separation

  • @aj_hari_7
    @aj_hari_73 ай бұрын

    We need consistent videos from Sin Jazzz 🎉

  • @NikolayVeselinov
    @NikolayVeselinov3 ай бұрын

    Alright, im ready for the next video, keep em coming!

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Soon

  • @junhuama68
    @junhuama683 ай бұрын

    Thank you so much! This is pure and simple to understand! Nice haircut! SO SO SO Looking forward to the next episode!!! Thank you again!!!!

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Thank you! Coming soon

  • @krypton_dev
    @krypton_dev3 ай бұрын

    Thank you sinaaaa ❤

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    ♥🙏

  • @alexngiifamily
    @alexngiifamily3 ай бұрын

    I am in Love with your explanations Bro. It's Amazing.

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Tysm!

  • @davidag90
    @davidag903 ай бұрын

    Someone has been watching "Succession" hahaha hahahaha. Thanks a lot Sina, your content never let me down. Cheers!!

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Thank you! Good show.

  • @SebastianFinkel
    @SebastianFinkel3 ай бұрын

    Nice one! ❤

  • @maannikita
    @maannikita3 ай бұрын

    hey, I love your teaching style. please make a video on Garbage collection and circular referenced objects.

  • @GiggleSnips
    @GiggleSnips3 ай бұрын

    Your videos are really great ❤ thankyou. I request you plz do videos on React Hooks

  • @ianfrye8988
    @ianfrye89883 ай бұрын

    Also the no side effects is so important in state management and the core concept of libraries like redux. Never modify state directly. Only return an updated state

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Yes!

  • @val-do
    @val-do3 ай бұрын

    Your edits are awesome

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Ty!

  • @ianfrye8988
    @ianfrye89883 ай бұрын

    One reason I love typescript. It catches a lot of this

  • @sam_6480
    @sam_6480Ай бұрын

    Such a wonderful tutorial ❤ Would you do an episode about design patterns and maybe software testing in the future?

  • @ColorCodeio

    @ColorCodeio

    22 күн бұрын

    Good ideas

  • @DevCoder
    @DevCoder3 ай бұрын

    Welcomeee baaack🔥🔥🔥🔥

  • @ColorCodeio

    @ColorCodeio

    3 ай бұрын

    🙏🏼

  • @chetansingh575
    @chetansingh5753 ай бұрын

    Thank You for this video. ❤

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    You're welcome

  • @dhiflaouibelgacem8146
    @dhiflaouibelgacem81463 ай бұрын

    Thank you for your efforts

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    You're most welcome

  • @keja5512
    @keja551219 күн бұрын

    Pure presentation of Pure func👍👍

  • @bmehder
    @bmehder3 ай бұрын

    The best tutorials.

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Ty!

  • @creed_forever
    @creed_foreverАй бұрын

    So creative representation.

  • @NadaII
    @NadaII3 ай бұрын

    Coding fact: If you write a function that sets the CSS variable for Sina's hair to 'hidden' and attach an onClick, you can transform him into Stanley Tucci. Add a 0.5s ease-in-out for a smoother transition. This is based purely on the thumbnail to this video btw..

  • @ColorCodeio

    @ColorCodeio

    3 ай бұрын

    Comment of the year 🏆

  • @davidvernon3119
    @davidvernon31193 ай бұрын

    Great video, great singing. I would add that while you can write pure functions in JavaScript, the language doesn’t support them the way some fancier languages do. For example in rust all functions are pure by default and the compiler guarantees this and you have to declare your intentions to be impure (to sin) by including self as an argument.

  • @hilariousness4393
    @hilariousness43933 ай бұрын

    I was hapoy to see you in my notification panel

  • @BSEFM-MUHMMADFARAZALI
    @BSEFM-MUHMMADFARAZALI3 ай бұрын

    Great Job Sina! Amazing content.👑 Kindly post react content as well

  • @RostyslavNazarenko
    @RostyslavNazarenkoАй бұрын

    Can we have a video in unit testing? But I'll probably learn it by myself till then) but I love your videos and type of teaching, and of course, I love you ♥😍😍

  • @ciprianparaschiv7591
    @ciprianparaschiv75913 ай бұрын

    Salut to you as well, from Romania. Great series, my dude. You could fit right into a real brick-and-mortar University as a cool JS teacher.

  • @sergiu6650

    @sergiu6650

    3 ай бұрын

    Salut tot din Romania.

  • @ColorCodeio

    @ColorCodeio

    3 ай бұрын

    Hello Romania! 🇷🇴

  • @sebastianguerrero5629
    @sebastianguerrero562914 күн бұрын

    Hi Sina, amazing work bro I would like to suggest this topics for future videos: 💎 Getters and Setters 💎 Short circuit operator 💎 Event Propagation Thanks for the quality of the content, greetings from Colombia

  • @215Leon215
    @215Leon2153 ай бұрын

    Been waiting so long for this series to continues! So glad that your back!

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Ty!

  • @mohamadhag6338
    @mohamadhag63389 күн бұрын

    The inventor of fun JavaScript:

  • @karlstenator
    @karlstenator3 ай бұрын

    It can be argued that a function executing a console.log is an impure function, as its side-effect is writing to the console.

  • @ColorCodeio

    @ColorCodeio

    3 ай бұрын

    Absolutely correct

  • @behindthescene4406
    @behindthescene44063 ай бұрын

    I been waiting since long 😭😭😭😭

  • @user-ej6lu1kx7p
    @user-ej6lu1kx7p3 ай бұрын

    Javascript legend is back 🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳

  • @ColorCodeio

    @ColorCodeio

    3 ай бұрын

    🕺🏻🙇🏻‍♂️

  • @renzodiaz5996
    @renzodiaz59962 ай бұрын

    I hope we get a "Qoli" face reveal by Episode 20 :) Awesome video man!

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    It's a possibility 🤨

  • @puyakhalili
    @puyakhalili2 ай бұрын

    Amazing video thanks a lot Sina. BTW how do you get the code continuously running on the right pane? is that Quokka ? and how do you get it to run in a separate column?

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    It's called RunJS - Here's my affiliate link: runjs.app/colorcode

  • @puyakhalili

    @puyakhalili

    2 ай бұрын

    @@ColorCodeio Wow incredible! Thanks Sina :) BTW I love the Gholi cameos in your videos! Our beloved childhood friend ;)

  • @Diego_Cabrera
    @Diego_Cabrera2 ай бұрын

    Sir you’re an amazing teacher. I aspire to be as clear and concise with my videos as you are. May I ask how you do you color grade your videos (lut or preset?) bc they’re beautiful. Also how do you edit your self right beside your editor? Is it a template for your screen recording or editing software?

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    It's got more to do with lighting and a good lens than software. Watch some tutorials on lighting before getting into LUTs, then you can do color correction based on your environment.

  • @raghavenderkuppireddy7158
    @raghavenderkuppireddy71583 ай бұрын

    Waiting ... && ❤❤❤🎉🎉🎉

  • @RobertMcGovernTarasis
    @RobertMcGovernTarasis3 ай бұрын

    Really curious, what is the tool you are using for the live coding? Looks useful, particularly for learning / testing ideas.

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    It's called RunJS. Here's my affiliate link: runjs.app/colorcode

  • @IlPandax
    @IlPandax3 ай бұрын

    You deserve a lot more credits for your videos. ;) Anyway, may I ask a video about the semi colon? Is it good, is it bad, why was removed... :D

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    I don't use them in these tutorials just to make things a little cleaner, and it doesn't really have an impact with some rare exceptions in return statements

  • @IlPandax

    @IlPandax

    2 ай бұрын

    @@ColorCodeioAh ok! Thanks! :D

  • @denisveli9465
    @denisveli946526 күн бұрын

    Thank you for the amazing content! Sorry about the awkward questions but I really like you glasses. Could you tell me the brand and the model, please? Thank in advance and keep up with the videos you're doing!

  • @ColorCodeio

    @ColorCodeio

    22 күн бұрын

    www.warbyparker.com/eyeglasses/dawson/azure-crystal-with-oak-barrel

  • @amirkishk
    @amirkishk3 ай бұрын

    Finally 🎉🎉🎉🎉🎉

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    🎉

  • @creed_forever
    @creed_foreverАй бұрын

    Rule 1 : one-to-one relation

  • @ivo_sa
    @ivo_sa2 ай бұрын

    when is your course dropping ? cant wait!

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Working on it as we speak. Make sure you join the list on www.colorcode.io

  • @cholo2605
    @cholo26053 ай бұрын

    GOAT!

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    🐐

  • @opencode1
    @opencode13 ай бұрын

    wooooooohoooo you da best :))))

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    So are you

  • @user-vo8hn7yj7z
    @user-vo8hn7yj7z3 ай бұрын

    Hi, Please let me know how to use spotlight effect on Mac mouse, thanks!

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    boinx.com/mousepose/

  • @paternyao
    @paternyao2 ай бұрын

    Starting at 3:00, how do you access this clear code editing space in the browser? Which browser is it? How do I access this window? It’s so clean!

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    RunJS.app/ColorCode

  • @shinigamiryoutaro
    @shinigamiryoutaro3 ай бұрын

    He actuallyt made me drink water.. thanks yo

  • @ColorCodeio

    @ColorCodeio

    3 ай бұрын

    Stay hydrated! 🚰

  • @CLeovison
    @CLeovison3 ай бұрын

    Can you please do a video about side effect?

  • @ColorCodeio

    @ColorCodeio

    3 ай бұрын

    I cover side effects in this video

  • @endfine9230
    @endfine92302 ай бұрын

    I came looking for copper and found gold

  • @asi7377
    @asi73772 ай бұрын

    what code editor you are using? i want that simplicity

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    RunJS.app/ColorCode

  • @copytopgrade6458
    @copytopgrade64583 ай бұрын

    hello, what font do you use ?

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    monaco

  • @shahidshafi1227
    @shahidshafi12273 ай бұрын

    Extension for console??

  • @ColorCodeio

    @ColorCodeio

    3 ай бұрын

    RunJS.app/ColorCode

  • @badr5465
    @badr54653 ай бұрын

    aleluya! hehe

  • @longingbydesign
    @longingbydesign3 ай бұрын

    "JavaScript MasterClass Available Spring 2023" ...

  • @ardavural4649
    @ardavural46493 ай бұрын

    where is ur podcast :(

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    After the full JS course

  • @djhi-tek9249
    @djhi-tek92493 ай бұрын

    Are you a syrian living in turkey ?

  • @logicmonster6197

    @logicmonster6197

    3 ай бұрын

    Bro he is definitely an Indian American

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Neither

  • @PooriaHana
    @PooriaHana23 күн бұрын

    salut('Logan') never can be a pure function! It can unexpectedly return "Fu*k off" :))

  • @fukkoff2024
    @fukkoff20242 ай бұрын

    Your videos are absolutely 🔥. Dude, dope a$$ jacket 🫡

  • @ColorCodeio

    @ColorCodeio

    2 ай бұрын

    Thanks! 🤘

  • @mohamadhag6338
    @mohamadhag63389 күн бұрын

    The inventor of fun JavaScript:

Келесі