Coding Challenge #15: Object Oriented Fractal Trees

Поділитися
Вставка
  • Опубліковано 20 вер 2024

КОМЕНТАРІ • 233

  • @hey8174
    @hey8174 7 років тому +291

    Dude this guy makes me so happy.

    • @seditt5146
      @seditt5146 6 років тому +2

      Really? He drives me insane, all I can think is that Meth is a horrible drug when I watch this guy, I like the Tutorials I just wish he would STFU for two seconds. IDK to each his own I guess, whatever makes ya happy for you and him.

    • @espnpokerclub1246
      @espnpokerclub1246 6 років тому +18

      me too his energy is contagious. He is obviously a wonderful human being,

    • @dannywest749
      @dannywest749 6 років тому

      Tooooo many extra curricular spasms in relation to his coding spawn. Lots of 'branch' words with no real goal established. He seems amazing....amazed with himself more so. Teach is like code...both require a plan to better results.

    • @BlackSlimShady
      @BlackSlimShady 4 роки тому

      @@dannywest749 "extra curricular spasms" Where? Sure he talks a lot, and brings up heaps stuff. But it is all relevant information, dont go watching a programming video and than when someone brings up a concept call it extra curricular, he is simply teaching us all the concepts involved.

    • @BlackSlimShady
      @BlackSlimShady 4 роки тому

      @@seditt5146 I dont think meth heads know how to code, keep a train of thought and explain what they are doing clearly all at the same time.

  • @Dennis450D
    @Dennis450D 8 років тому +265

    Criminally underrated channel imo. Really glad that I found this, loving the videos so far.
    Keep it up!

    • @TheCodingTrain
      @TheCodingTrain  8 років тому +25

      thank you for watching!

    • @nirajgaonkar7669
      @nirajgaonkar7669 7 років тому +1

      thank you for making

    • @benjaminphilippe2810
      @benjaminphilippe2810 7 років тому

      I found a coding train video on the suggestions bar when I was watching some other programming video and thought "Why not?". Ever since I've been watching your vids. Just BECAUSE.

    • @louisrobitaille5810
      @louisrobitaille5810 4 роки тому +1

      Only sad thing is that he mostly does js and not other languages. Would be nice to see this in c#, java, c++, etc.

    • @kokorogames61
      @kokorogames61 3 роки тому

      @@louisrobitaille5810 code can be adapted. I m doing some of these in gamemaker's studio, which is a game engine with its own language. 😁

  • @TheJaredtheJaredlong
    @TheJaredtheJaredlong 7 років тому +59

    Just subscribed. I don't code. Honestly not even interested in doing any coding. All these videos are just so fascinating and make me happy.

    • @snowjix
      @snowjix 4 роки тому

      @- RedBlazerFlame - DUDE, downloading terraria isnt coding.

    • @v0xl
      @v0xl 3 роки тому

      @R09 Gabee De Vera With chunk loading?
      And why did you choose python?

  • @netoskin
    @netoskin 7 років тому +54

    Dude im a beginner in the code universe and your vids are simply awesome cant stop watching! Thank for giving us this content

  • @qualle987123
    @qualle987123 Місяць тому

    I made a similar thing after your first Video about fractal trees. But I just stored the angle of the branch. I then recueisvely added a left/right branch with the parents angle -/+ some constant. Saves you a lot of work with vectors, in my opinion. But this approach clearly works just as well. Great video as always.

  • @raedtabani2236
    @raedtabani2236 7 років тому +4

    I've been trying to read the book "algorithmic beauty of plants" and this so far is the best source for understanding , thank you so much :)

  • @SchokoGames
    @SchokoGames 8 років тому +11

    i would love to have you as a teacher at our local university, because you are such a congenially person (: keep up the good work! the quality of your videos is amazing!!!!!

  • @dnz8792
    @dnz8792 7 років тому +32

    Very cool man!
    I have no experience with javascript and I really enjoyed it!
    Thanks

  • @6ickbeats
    @6ickbeats Рік тому

    As a beginner of javascript, I really really appreciate your inspiring contents!! You made coding so much fun!

  • @Sfbaytech
    @Sfbaytech 7 років тому +6

    You have made watching coding fun. That is pure talent!

  • @bartdemeyere
    @bartdemeyere Рік тому +1

    Excellent video. I created this tree with growing branches with random angles and put the entire tree rendering into 1 object. Now i can create multiple trees at once and let them growing. I didn't use p5 but vanilla javascript and html canvas.

    • @qualle987123
      @qualle987123 Місяць тому

      Sounds awesome. I practically did the exact same thing also by using vanilla JS.

  • @kim15742
    @kim15742 6 років тому +1

    Quite surprising how simple this is, in the sense that you can create really realistic trees with this method, because trees are nothing other than branches branching into more branches

  • @tonchete8054
    @tonchete8054 6 років тому

    Managed to make it change color with each click! Might be easy, but its not when you have no idea about codding.
    Thanks alot for this videos, well explained and fun to watch, perfect for summer nights.

  • @andrewemery1140
    @andrewemery1140 6 років тому +44

    Hey it's been almost two years so here is your reminder to come back to this and add physics to the tree !

    • @TheCodingTrain
      @TheCodingTrain  6 років тому +21

      Oy, thank you! I might need another reminder this summer 🙏

    • @mosef312
      @mosef312 5 років тому

      @@TheCodingTrain soo.. did you do it?

    • @sanchitverma2892
      @sanchitverma2892 5 років тому +4

      @@TheCodingTrain reminder to add physics to the tree

    • @lucasj.pereira4912
      @lucasj.pereira4912 5 років тому +3

      @@TheCodingTrain and I'm remembering the rememberer.

    • @lingling2454
      @lingling2454 4 роки тому +4

      The Coding Train REMINDER FOR PHYSICS :D

  • @kristiangullner1904
    @kristiangullner1904 7 років тому +1

    It is 2017! Attach spring forces! Great videos! Just learning p5/JavaScript thanks to you! Really great content!

  • @vanguardgaming8435
    @vanguardgaming8435 7 років тому

    I created a single tweaked branch function instead of two branch functions it works pretty well here is the code:
    this.branch = function(a) {
    var dir = p5.Vector.sub(this.end, this.begin);
    dir.rotate(a);
    dir.mult(0.67);
    var newEnd = p5.Vector.add(this.end, dir);
    var right = new Branch(this.end, newEnd);
    return right;
    }
    and is used like so:
    tree[1] = root.branch(PI/4);
    tree[2] = root.branch(-PI/4);

  • @overwhelmingsarcasm
    @overwhelmingsarcasm 7 років тому

    Wow! I'm only beginning to learn to code now, but through your videos I've found awesome inspiration to put all the maths I've learned at school into use while coding. Fantastic work, keep it up!

  • @Khrysopos
    @Khrysopos 3 роки тому

    That was hands down the most awesome programming video I've ever seen.

  • @avatar098
    @avatar098 8 років тому +24

    Where in the heck were you when I first started my comp sci career..

  • @lazyglimpse
    @lazyglimpse 2 роки тому

    That's genius! Accidental lines of code just created a surprising and touching art!
    I am quite enjoying your work and it inspires me a lot. A Big Thank you!
    And I think it's safe to jump out of the loop after checking it's true, because you loop reversely and previous item must be set to true already.

  • @daniaste
    @daniaste 2 роки тому

    You are a genius. Thanks for all!
    I purchased one of your books. It is brilliant.
    Thanks, thanks, thanks.

  • @addnoobs
    @addnoobs 7 років тому

    Another way to go about storing the branches is to have the branches stored inside of its parent branch, so a branch object would have childBranches, or branchA and branchB, depending on how you want to store the branches, then the branches show() function can call show() on its children

  • @saadouch
    @saadouch 5 років тому +2

    i actually made in python a function that draws an oval and gives ir a random color between brown orange red and pink and a rondom angle wich makes the tree look supper realistic

  • @TheDronings
    @TheDronings 6 років тому +1

    Thanks for the videos! I've been binge watching and reading the Nature of Code. In this video you told us to remind you to do a video on "string forces" so you can pull objects and have them spring back - did you ever make that video? Sounds super interesting!

  • @Fadingbeat
    @Fadingbeat 7 років тому +21

    hahahaha you're extremely funny, and smart. so, would you guys suggest to use p5 with processing rather then just processing?

    • @TheCodingTrain
      @TheCodingTrain  7 років тому +10

      +Fadingbeat I use them both. Depends on what I'm doing!

  • @anamariaarbelaezlopez4783
    @anamariaarbelaezlopez4783 Рік тому

    Thank you!!!! You are such a great professor, very useful tutorial!

  • @behrampatel3563
    @behrampatel3563 3 роки тому

    5 year reminder. Do the jitter with spring forces . You asked @ 18:33 ;)

  • @espnpokerclub1246
    @espnpokerclub1246 6 років тому

    You may be able to integrate the Edwards Lorenz attractor thing you did in an early video.the one where it drew two intersecting ellipses in color and 3d. During that demo, you vectored the result and a strange "shimmering effect happened. Perhaps you could apply THat to the leaves to give the impression of wind, and then cycle through 3 or 4 different lorenz arrays to make it more random.

  • @kevnar
    @kevnar 2 роки тому

    Fractal trees + forward kinematics = infinite fun

  • @Absiii
    @Absiii 6 років тому

    Would be interesting with a coding challenge where you took fractal trees into your landscape generate code. And with rules planeted the trees related to reality where trees doesnt grow over a certain height.

  • @tamarpeer261
    @tamarpeer261 5 років тому +2

    Branch to the right! Branch to the left!

  • @RyanDurbin10
    @RyanDurbin10 7 років тому +2

    I absolutely love your videos!!!

  • @adrianperea4026
    @adrianperea4026 4 роки тому

    You are so insightful. Thank you so much.

  • @blocksWithJofri
    @blocksWithJofri 7 років тому +5

    Do you have a discord? If not maybe you should do one. I think it is a great platform where people can help each other with coding

    • @TheCodingTrain
      @TheCodingTrain  7 років тому

      +Joo friii what's discord?

    • @blocksWithJofri
      @blocksWithJofri 7 років тому +4

      Oh, its an Teamspeak and a Forum in one. You can create a Server where you can create Text channels with different topics and voice channels too. Many Twitch Streamer (Gamer) you this, but I think it would work for your channel too. Its for free to create a server, so definitely check that out.

    • @creepy99
      @creepy99 7 років тому

      It's a voice and text chat app that is free. You just create a channel (or channels), share them, and people show up and chat. discordapp.com/

  • @penny2515
    @penny2515 4 роки тому

    Reminding you to add springs to this array!!!

  • @rossthemusicandguitarteacher
    @rossthemusicandguitarteacher 5 років тому

    This guy is awesome

  • @williamherewini8357
    @williamherewini8357 5 років тому

    (18.24) Do a video where we take this tree and actually attach spring forces to all of it, so you can sort of pull on it and it just goes "blrvwvrvwvmnvm"

  • @am8537
    @am8537 Місяць тому

    I wonder if, 8 years later, OOP is still the best approach to draw the tree. I find the vector part unnecessarily complicated.

  • @liyaha.6867
    @liyaha.6867 7 років тому

    You should do a video so we could get to know you .. cause I have a few questions you should answer Love your channel btw I'm just getting into computer science I would also like you to do tutoring I need help on the basics but I prefer to learn from you... you have the energy

  • @chiletv2936
    @chiletv2936 6 років тому

    Hi coding train, you can do a challenge like a paint, but in javascript, you will can draw with mouse, erase like a rubber, etc

    • @midnightrizer
      @midnightrizer 5 років тому

      He does that in the coding train series he does.

  • @xenoxg5102
    @xenoxg5102 5 років тому

    I thougth about this in school
    and i CAME to the same thing
    I m proud of myself

  • @jihosong9392
    @jihosong9392 7 років тому

    I have questions!
    1. why does prccessing works well while using var in iterating loop? I thought in javascript there is always problem using var in loop statement, so it is encouraged to use let.
    2. when you use jitter method, why do not entire branches goes off uncontinuosly? Shouldn't it appear like bunch of segmented sets of branches since we are only moving the end points??

  • @twistedsim
    @twistedsim 8 років тому +5

    That's a nice tree ! :)

  • @vladimir_egay
    @vladimir_egay 6 років тому

    16:56 I might be wrong but shouldn't you put "tree[i].finished = true" inside of the "if" statement. Cause after you add branches it is finished!?

  • @thatdooddillon
    @thatdooddillon 7 років тому

    Any resources to start what you talk about at the end? Really like the idea of playing with the realistic nature effects but am not that experienced of a programmer, thanks Dan!

  • @justriseandgrind4059
    @justriseandgrind4059 5 років тому

    this just blew my mind!!!

  • @quebono100
    @quebono100 6 років тому +1

    Please, could you make an pythagorean Tree, I would love to see one

  • @youssef7206
    @youssef7206 7 років тому

    that's a happy coding chalenge XD
    keep it up...

  • @sreeharylaiju
    @sreeharylaiju 4 роки тому

    The beginning is the end. The end is the beginning. Everything is connected. 😂😂

  • @namelastname4077
    @namelastname4077 4 роки тому

    would have been so cool if you had done it with three.js

  • @liamonica7768
    @liamonica7768 3 роки тому

    Thank you so much Sir! I find out your channel is amazing! You gain a new subscriber here :D

  • @MartinStacey
    @MartinStacey 7 років тому

    Really cool video! is there a way to mantain the tree structure so that the branch knows which his parents are??

  • @rajatpatel1817
    @rajatpatel1817 3 роки тому

    Was literally worked on this for 2 hrs and then i found his video.. lol

  • @kim15742
    @kim15742 6 років тому

    Heh, I didn't even watch the video, I challenged myself to come up with the ideas, and at 15:00 I did it exactly the same way, but that was quite a spontaneous thought, I had no idea how to do that previously

    • @kim15742
      @kim15742 6 років тому

      Ok, the reverse for-loop is quite clever. I firstly calculated that the number of branches _b_ based on the order of the branches _o_ : _b(o)=2^n-1_

    • @kim15742
      @kim15742 6 років тому

      And then, when I started with random generation, I just did it, until the order was 8

    • @kim15742
      @kim15742 6 років тому

      Ok, he calls order count, if anyone is confused

  • @aroraqueen1555
    @aroraqueen1555 4 роки тому

    I really can't stop watching it , and I want to try it ,but which program do you use ?? and which language do you use ? is it java ?? because I try to make it with visual studio but it didn't work and I don't know why

  • @maksymvyshnianchyn6791
    @maksymvyshnianchyn6791 4 роки тому

    hey, i'm fairly new to all this drawing; thanks for your work!
    how would you write a loop for count, that the leaves are added not only the first five counts, but every five counts?

  • @PhysicsMarc
    @PhysicsMarc 7 років тому

    So I will often make sketches that need to have a dynamic canvas. Meaning, there is some content that moves around and needs to be centered on the screen, or in this case, the canvas needs to dynamically resize as the tree gets larger and larger. Is there a recommended method for doing this? I have found some methods that work, but there is some performance impact

  • @TheArtheanos
    @TheArtheanos 2 роки тому

    Writing function objects in Atom, those were the times...

  • @mogwyrependelhurst1947
    @mogwyrependelhurst1947 7 років тому

    How can I stop the tree from growing past a certain count, say 6 mouse clicks? Currently it just keeps growing until it crashes, and I want to constrain this function.

  • @matteobarberis1069
    @matteobarberis1069 6 років тому

    what do you mean when you say that all those branches store their location dynamically? i've tried to do the same with processing but the when i try to jitter the branches they go where they want without staying attached to each other because their position is not updated.

  • @danny_racho
    @danny_racho 4 роки тому

    I know this is a little bit late, but how do you adjust your lines like this? When you write for example (a,b) and then you press something and that turns it to (a, b). It also works perfectly with For-loops. I am missing this in my Text-editor and don't know how to find it by googling. Is it called reformation?

  • @JoseDavid-bv8lo
    @JoseDavid-bv8lo 7 років тому +2

    "I hear voices!" \0/

  • @space-nu6hc
    @space-nu6hc 7 років тому

    If i wanted wind to be affected by the tree, how could i do that. And can you please make a video on that.

  • @MultiLeandrini
    @MultiLeandrini 6 років тому

    Time to make the spring forces? ahahah
    I would love to see that.

  • @aidanbenbow6682
    @aidanbenbow6682 Рік тому

    Did you ever do the springy tree video?

  • @dennis8171
    @dennis8171 7 років тому +2

    i dont get how that jitter works. if you move all the end positions how does the next branch now to update its start position? the only function being called every frame is the draw and jitter and the jitter only changes the end position not the start?? can someone explain sorry for my shitty english

    • @dennis8171
      @dennis8171 7 років тому

      is it a pointer? or am i just missing something

    • @yoshivb
      @yoshivb 7 років тому +2

      Javascript is a bit tricky in its memory management. Because the vector is an Object if you assign it to a variable it will not copy that Object but instead reference it.
      So the begin vector is just referencing the end vector of the previous branch.
      If this is not the behavior you want p5.Vector has a copy() function which creates a copy of that vector.
      I hope this makes it clear.

    • @dennis8171
      @dennis8171 7 років тому

      +yoshivb Thanks for explaining

  • @kalolewalow
    @kalolewalow 8 років тому

    Hi, I think that your coding challenges are wonderful! Could you remind me of how I could get started with coding on my mac? What program should I use to be able to run and modify the code in this particular video and where could I find the code? Thank you a lot :)

    • @TheCodingTrain
      @TheCodingTrain  8 років тому

      You can get started here: p5js.org. I'm using a text editor ("atom") in this video and following this methodology: ua-cam.com/video/UCHzlUiDD10/v-deo.html

  • @krinjon193
    @krinjon193 5 років тому

    i dont under stand how those branches are staying conneceted if we are randomizing the only the end of the lines.
    there is no code connecting the all the branches that tell each other that their previous branch end point is what the begin point of current point.

  • @keitaidrissa312
    @keitaidrissa312 6 років тому

    Very nice video. Thanks

  • @amairivas6310
    @amairivas6310 6 років тому

    Does enyone know something similar to thse videos, but in C#? It would be awesome! Thanks.
    By the way, love this videos, man!
    Keep up the good job!

  • @karenghazaryan3578
    @karenghazaryan3578 5 років тому

    Is it right that branch drow himself?I think in oop you cant write some function like drow in class.Am i right?

  • @kim15742
    @kim15742 6 років тому

    Working with references in JS is quite error-prone through its implicicy (is that a word)?

  • @randytruong7562
    @randytruong7562 4 роки тому

    Is there a Processing Java version of this? I've managed to get everything up to the push() function in mousePressed() {} and this push() function seems unique to p5-- unless judging by how the loop starts from the end, it kind of resembles a stack?

    • @randytruong7562
      @randytruong7562 4 роки тому

      Nevermind, I got it! I used an ArrayList

    • @codycodes7527
      @codycodes7527 3 роки тому

      in java it is add and push is javascript not p5

  • @cuzrsedo
    @cuzrsedo 2 роки тому

    to multiply the tree , where do you write the loop

  • @ayushrajniwal
    @ayushrajniwal 6 років тому

    It was so beautiful....I love it!!

    • @TheCodingTrain
      @TheCodingTrain  6 років тому +1

      thank you!

    • @ayushrajniwal
      @ayushrajniwal 6 років тому

      The Coding Train oh my god thank you sir for replying me.....😭😭😭😭😭💜

  • @kim15742
    @kim15742 6 років тому

    Hm, swaying with perlin noise? I just sway with sin and a random coefficient

  • @jalindarjagtap4407
    @jalindarjagtap4407 6 років тому

    Please tell us how do all these things. We like to understand it.

  • @mrkinetic
    @mrkinetic 6 років тому

    Could have just only called the branch methods on the last item in the array. tree[tree.length - 1].branches();

  • @Ensivion
    @Ensivion 7 років тому

    Hey, I tried impementing this in python using PIL , specifically Image and ImageDraw (with numpy vectors for ease of vector operators) and was mostly successful. The people who created the library said it's not particularly good at making lines look better and was wondering if you know any better ways of implementing this. The lines have jagged edges that aren't in your image, and I just put it through an anti-aliasing filter in GIMP which did help a bit but I think it needs to be fixed when it's drawn. Part of me wants to join you using Processing but I don't know any java or javascript.

    • @tcchan14
      @tcchan14 7 років тому

      Hi, I am using pygame in python to do the same code. It is more difficult and challenging because I have to implement function which doesn't exist in pygame like map, translate, Createvector etc.
      This time I have learnt something new and never thought about.
      Using a class function to create a new class object and using a for loop in reverse order to avoid infinite loop :D

    • @sadhlife
      @sadhlife 6 років тому

      you'll be surprised how similar Python and JavaScript are. I have a python background too but I actually learned all of JS that you see in these coding challenges in a week from the tutorial playlists on this channel.

  • @clambert2370
    @clambert2370 7 років тому

    Awesome!

  • @ColeJT
    @ColeJT 7 років тому

    You've created neature.

  • @Buinhikl
    @Buinhikl 4 роки тому

    Hello, could anyone explain to me how to have your right tab view to access libraries? I manage to download atom, install and open the file already.

  • @mintunath9267
    @mintunath9267 6 років тому

    just you are amazing

  • @josejacob99
    @josejacob99 7 років тому

    thanks man

  • @darthtorus9341
    @darthtorus9341 8 років тому

    well I think I have ideas for the leaves :3

  • @mace-create
    @mace-create 6 років тому

    Smart man

  • @kranser
    @kranser 7 років тому +3

    Why store the main tree object, can't each branch have an array of 2 vectors and then the data is not stored in one place, but each branch object has details of it's sub branches...?

    • @soniavecchini9658
      @soniavecchini9658 7 років тому

      kranser wouldn't that be too complicated?

    • @TheMonkFilm
      @TheMonkFilm 7 років тому

      Exactly what I was thinking. No need for the global tree array. Kinda takes away the recursion

    • @Imaboss8ball
      @Imaboss8ball 7 років тому

      TheMonkFilm this isn't recursion on purpose. it's a different technique

    • @yoshivb
      @yoshivb 7 років тому

      That would be a binary tree. Binary tree's are wonderful data structures and definitely something to learn about but this video was more aimed towards using an object oriented approach so it's the basics. Thus I can imagine Daniel wanted to keep it basic. But binary trees are definitely the way I would have gone about when creating a fractal tree.

    • @kitestringgaming7399
      @kitestringgaming7399 5 років тому

      Uhhhhhhhhhh......yes?

  • @olfmombach260
    @olfmombach260 7 років тому

    What's the difference between
    _var a = createVector(42, 24)_
    and
    _var a = [42, 24]_
    ?

    • @Kino-Imsureq
      @Kino-Imsureq 6 років тому

      nothin

    • @jayant_4791
      @jayant_4791 6 років тому

      So a vector has some functionality that you might expect from "vectors" like the one dan used in the class , the add and sub functionality whereas in case of array you don't have that kind of comfort

  • @IkkeVanAdel
    @IkkeVanAdel 7 років тому

    Hi, first time I used P5.js. Somehow I noticed that these build-in event functions do not work for me :( . I have been following your tutorial exactly but it does not recognize the function mousePressed(){}. Any idea ?

    • @TheCodingTrain
      @TheCodingTrain  7 років тому

      Can you post your code and question to forum.processing.org?

  • @ishi92
    @ishi92 7 років тому

    Hey Dan, Im trying to recreate this code in openFrameworks. Could you explain why you use "this.x" ?
    Cheers!

    • @robertwagner8507
      @robertwagner8507 7 років тому +1

      Basically it's saying that anything can use the x function

  • @leberkassemmel
    @leberkassemmel 7 років тому

    this. is like self. in a lot of other languages.

  • @justinasbei
    @justinasbei 6 років тому

    I hate recursive trees. This is much better.

  • @tobyzxcd
    @tobyzxcd 7 років тому

    10:28 just wondering, does the "other" side of the pen do anything special ?

    • @humbledeer
      @humbledeer 7 років тому +1

      It's the worn out side, I suppose. :P

  •  4 роки тому

    Why this series is in spanish but the others not?

  • @williambillemeyling5647
    @williambillemeyling5647 7 років тому

    i am going to use for a school project where I will animate cancer cell mitose

  • @yerramillirohith5720
    @yerramillirohith5720 7 років тому

    no words to say. u really rock. If i got an army or superpower , i would make all people in world subscribe and vaporise all those who disliked .

  • @cohemo077
    @cohemo077 7 років тому

    Is there a way to do this in Porcessing?

  • @DaleBasye
    @DaleBasye 8 років тому

    ThanX

  • @luisaisat
    @luisaisat 5 років тому +1

    la poo es fantastica

  • @timurtu
    @timurtu 7 років тому

    why not say if(currentBranch) instead of if(currentBranch == null)? This checks if currentBranch is truthy

    • @charbelsarkis3567
      @charbelsarkis3567 7 років тому

      Timur Uzel yeah but that would check if it's true or false not if it's null

    • @timurtu
      @timurtu 7 років тому

      Falsy in JavaScript includes null, undefined, and 0
      function logIfExists(val) {
      if (val) {
      console.log('This line never gets logged')
      }
      }
      let falsyVal = null
      logIfExists(falsyVal)
      falsyVal = undefined
      logIfExists(falsyVal)
      falsyVal = 0
      logIfExists(falsyVal)

    • @charbelsarkis3567
      @charbelsarkis3567 7 років тому

      Thanks for the enlightenment

    • @timurtu
      @timurtu 7 років тому

      Yes it's good to know I think it looks cleaner although you might need to think of the cases. Empty string is also falsy but empty array and empty object are truthy