Top 10 Javascript Tricks You Didn't Know!

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

КОМЕНТАРІ • 404

  • @cromrin
    @cromrin 5 років тому +301

    0:00 Intro
    0:45 Ad
    1:38 Setup
    1:46 Turnary Magic
    6:19 Number To String
    7:12 Fill Arrays
    8:00 Unique Arrays
    9:39 Dynamic Objects
    11:33 Slicing Arrays
    12:04 Slicing Arrays End
    13:21 Object To Array
    14:19 Performance
    16:20 Outro
    17:55 End

    • @Microphunktv-jb3kj
      @Microphunktv-jb3kj 5 років тому +8

      Ternary, not Turnary...

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

      I already know Turnary Magic, Slicing Arrays, Object to Array

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

      @@AhmedAli5530 Nooice

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

      same on css please, anyone :D

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

      Why *Dev Ed* didn't showed *Object.entries* for getting keys and values of object as array...

  • @ngtyt
    @ngtyt 5 років тому +83

    pro tip : add "+" before a string to coerce it into a number, and use string literals for the opposite. example:
    typeof +"5" //returns number
    typeof `${5}` // returns string

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

      Interesting. Actually learned something new. Thanks!

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

      toString() best way

    • @jaycee4738
      @jaycee4738 4 роки тому +8

      Why don't you just use parseInt or Number to convert string into number? as well as toString to convert it to string?

  • @urfriendalex.y
    @urfriendalex.y 5 років тому +160

    naming a constant variable “dynamic” is totally legit

    • @secretagentx-9908
      @secretagentx-9908 5 років тому +34

      The only constant is change.

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

      Lol

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

      XD lol

    • @urfriendalex.y
      @urfriendalex.y 3 роки тому

      @TECH VINEYY that’s to add a little bit of spice

    • @rajikkali2381
      @rajikkali2381 3 роки тому +2

      @TECH VINEYY I learned from his JS course that it can if it’s an object or array. Only single values are actually constant when using a const. Weird, right?

  • @boblitex
    @boblitex 5 років тому +57

    9:37 const unique = [... new Set(users)]
    even easier

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

      Exactly my thoughts! Though for older browsers with polyfill for Set Array.from is better but in node js and electron I always like the three dots for both arrays and objects :)

  • @tahasoft1
    @tahasoft1 5 років тому +13

    Be careful about fill array with an object. I faced a problem at my work using it because it will fill it by a reference to the object, not value
    so if any change happens to the object the array will be changed.
    Example:
    const obj = { a: 1 };
    const ar = Array(3).fill(obj);
    // ar = [{ 'a': 1 }, { 'a': 1 }, { 'a': 1 }];
    obj.a = 0;
    // [{ 'a': 0 }, { 'a': 0 }, { 'a': 0 }];

    • @labwax
      @labwax 5 років тому +6

      just do this
      const ar = Array(3).fill({...obj});

  • @phanthh
    @phanthh 5 років тому +126

    I just lost it at "unemployed techlead " lmao :)

    • @mel-182
      @mel-182 5 років тому +3

      it should be the millionaire techlead!

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

      @@mel-182 No, he lives in a shed. The (ex-Google!) tech-lead shows just another AirBnB...

    • @jamesikubi6831
      @jamesikubi6831 4 роки тому +3

      😂😂 I immediately scrolled to the comments at that point to see reactions. Too bad traversy is off youtube though

    • @adelm.3835
      @adelm.3835 4 роки тому

      @TechLead

  • @freakinmonkey85
    @freakinmonkey85 5 років тому +10

    Tip 10: use
    console.time(“My code timer”)
    //run code here
    console.timeEnd(“My code timer”)
    Much shorter, and you can create as many timers as you want by using different values

  • @woket4730
    @woket4730 5 років тому +80

    Top 10 React.js Tricks You Didn't Know! Please ;3

  • @denoww9261
    @denoww9261 5 років тому +21

    Hey, about the ternary stuff: normally you wouldn't put whole statements in there. At least that's how it works in most languages, not sure about JS. Since they're all console.log() statements, you could write it as:
    console.log(age < 18 ? "Underage" : "Of age")
    This is mostly used for when you have some boolean that decides a small part of an output. For example:
    console.log("The time is " + settings.use_12_hour_time ? time_in_12_hour_format() : time_in_24_hour_format());
    Of course the variable and function naming could use some work but you get the idea. And yes, I agree, chaining them looks pretty ugly in most cases.

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

      Yeah, I absolutely would have done it this way. Not that unusual a trick, either.

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

      That is most thoroughly explained, thank you for sharing.
      I want to know if you can use *block statements* in a ternary operator using curly brackets. I'm going to test right now, though.
      Edit: truth is, you have to use Immediately Invoked Function Expressions (IIFE) to use multiple statements in a ternary operator body.
      This would be kind of useless information as you could just switch to an if...else statement, which provides a scope easily.
      If...else statements also can do similar of what a ternary operator can do, if you omit the curly brackets.

  • @NoOne-ev3jn
    @NoOne-ev3jn 5 років тому +21

    "name": "ed",
    "occupation": "sex model",
    "hobbies": "licking doors" lol
    u r crazy man but you know what, I really love you :) thanks for everything

  • @tiagocunhafernandes6607
    @tiagocunhafernandes6607 5 років тому +13

    Ed, for performance you can use Console.time(“test”) before and Console.timeEnd(“test”) after and this show the time between time and timeEnd.

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

    your personality makes your videos so approachable and no boring

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

    Only 40 seconds into the video and I already know why I subscribed to you. You are such breath of fresh air. Thank you for being you, and thank you for posting videos.

  • @StrangeIndeed
    @StrangeIndeed 4 роки тому +2

    I've something to say about the trick at 11:00. I'm new to JavaScript, but I've noticed that you don't have to write [dynamic], you can omit the square brackets. But you have to write brackets if you want to access a property of an object. For example:
    const user = {
    firstName: 'John',
    lastName: 'Doe'
    }
    const userWithReversedProperties = {
    [user.firstName]: 'firstName',
    [user.lastName]: 'lastName'
    }
    console.log(userWithReversedProperties) // {John: 'firstName', Doe: 'lastName'}
    You have to use square brackets, otherwise you'll get an error. And yeah, I could come up with better names in this example.
    And like I said, I'm a noob, so maybe there is more to this and I don't know about it.

  • @AliRaza-kt2bb
    @AliRaza-kt2bb 5 років тому +13

    Like the way you talk! Just noticed something so sharing
    5:25 It should log "You are 50 or below 50 "
    5:37 It should log "You are between 50 and 70"
    By the way, I like the board in the background, "Gorgeous Friend" :)

  • @charbelmedia3014
    @charbelmedia3014 5 років тому +19

    I wanna to see Dev Ed Tech channel right here on UA-cam!

  • @JamesWelbes
    @JamesWelbes 5 років тому +24

    I want a shirt with Ed's face on it that says WHY YOU DO DIS?!

  • @jthomasaurus
    @jthomasaurus 5 років тому +6

    Dammit you’re hilarious, devEd. One of the most engaging channels I watch on the UA-cam

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

    Honestly one of the most enjoyable tips and tricks video I've seen. It's like hanging around with friends.

  • @incarnateTheGreat
    @incarnateTheGreat 5 років тому +3

    Great tips! Thanks for sharing!
    One thing: while the multiple Ternary example you did technically works, it tends to get messy to read and is somewhat discouraged. Usually, if the condition calls for a simple if/else, then a Ternary is ideal. Otherwise, it's probably worth writing out the old way.

  • @johnsamuel6096
    @johnsamuel6096 3 роки тому +1

    Javascript is magic for people who don't know the basic functionalities of every programming language

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

    I've been doing JavaScript every day and night for a few months now, trying to really master it. Also purchased a couple of your course videos. Just wanted to say thanks for the crazy entertaining videos. Very fun and helpful! Even my wife is into JavaScript now. But one thing, how did you even know that we're gorgeous?! You're freakin psychic, my JavaScript brotha!

  • @r0x304
    @r0x304 4 роки тому +12

    “They were on drugs when they did this” lmao

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

    your humour is what we all need.

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

    Alot of stuff I hadn't seen before.
    If I may tweak your ternary operator example some:
    console.log( "You are " + age > 70 ? "getting really old" :
    age > 50 ? "between 50 and 69" : "below 50" );
    This does two things. First it's a bit more concise than your version. But more importantly it illustrates the use of the ternary op where If/else is not allowed to go, like within function parameter lists.
    By the way, one super cool feature of JavaScript that I LOVE is the use of prototype functions to extend the basic types by, say, adding new functions. So instead of having to type [ var int = parseInt( str ) ], you could write: [ var int = str.i(); ] for example.

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

    Dude, you're so funny! The video is great anyway but the little things you throw in there like 'stealing from shops, no, what other hobbies do I have.." just make me laugh so much and actually restore my faith in humanity. You're awesome bro! Keep on rocking :)

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

    Also very useful: const objToArr = Object.keys( arr ).map( key => arr [key] )

  • @rudyNok
    @rudyNok 3 роки тому +1

    Nobody is going to point out how @ 5:35 he has the ages messed up and when the code says for the age of 60 that it is between 30 and 59 he says it works just fine? WTF?

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

      I was looking for this comment that's like 5th grade math 😂

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

    If you want the keys and values of the object into an Array you can use Object.entries()

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

    Your energy is always great.

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

    I would like to meet u once in my life to say Thank You
    ur every video make my day awesome nd improve my knowledge in languages....really

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

    Good content and keep up the good work.
    Instead of the ternary example(which ended up to be quite nasty), and highlighting another thing that people don't normally use, you could have highlighted the switch statements for ranges.
    switch (true) {
    case age > 70
    // log something
    break;
    case age > 50
    // log something else
    break;
    default
    // log the default

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

    9:19 Oh gosh... remember the classic interview question “Create a function that eliminates duplicates from an array”. Not anymore, I guess 😂

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

    0:00 Challenge Accepted...
    1-9 ... *yawn*
    10.. well sheeeet; didn't even know 'performance' was a word in js; i just use Date.now() on both ends.
    I mean it's not going to make a world of difference but for those wondering how it differs from using Date,now() the answer on the docs is the 'resolution'/'precision' Date is milliseconds and performance offers microsecond resolution.

  • @MrMamate
    @MrMamate 5 років тому +34

    "traversy daddy" lamo

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

    unemployed tech lead, travesty daddy !! lol lol lol I am laughing to death here. Nice one bro, I am sure it was all healthy humor. Love your energy - keep it up

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

      Of course, just poking fun a bit hehe

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

    With the Turnary operator you didnt need to console log each time, the useful thing about the operator is that it returns the value each time. You can use them this way instead: let msg = age > 50 ? "you are over 50" : "you are under 50"; console.log(msg);

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

    Stealing from shops ... your video is too good ! loved it.

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

    I thought you would show the really short ternary code! I don't know all the ins and outs of it, but its something like, if you want an If statement that runs only 1 line on completion, instead of taking up three lines to write
    if (true) {
    executeMethod()
    }
    you can instead write
    true && executeMethod();
    Or the inverse, if you want a false condition
    false || executeMethod();
    Like I said, I don't know all the ins-and-outs of writing this, it only seems to work sometimes. Was hoping you'd provide more details! Love the video btw

  • @0bbie610
    @0bbie610 4 роки тому

    Yes. Dev ed tech channel. I'd really love to see some game development though. I want to start developing some games but idk where to start haha

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

    Like your knowledgeable humour filled lively presentations

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

    Good Job Ed, U are getting better every video. Keep it up.👍
    And Oh "The Complicated Ternary Operator" with the accent cracked me up at even at 2:am🤣👍

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

    also, add a string to an integer which is '2' - 0 will get 2 return as integer type

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

    can u tell me what extension do u you use for making your code more cleaner plss

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

    Wow. Can't believe I knew all these and use all these tricks in everyday code.

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

    Thank You So Much Ed! I didn't know some of these so you helped me so much. :)

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

    you are the best who makes it fun while learning in youtube

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

    Thank U Brother Looking forward to 2020 to. and love to see @Dev Ed Tech, Love back End, T'c God bless u Brother From Australia;

  • @JohnyMorte
    @JohnyMorte 5 років тому +6

    In turnary operators is wrong logging.. should be "You are bellow 50" and "You are between 50 and 70"

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

      I was searching for this comment after noticing the mistake... Btw why no one noticing it...

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

      I thought I went insane in the membrane for a minute there

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

    when would shortening arrays with manually assigning .length be an actual good idea? I feel like that introduces the possibility of janked up arrays that aren't acting as expected leftover by mutating like that. wouldn't you prefer .slice() to be more explicit about which cut of the pie you're accessing in all cases?

  • @Murphy5-5
    @Murphy5-5 4 роки тому

    a cool thing with turnary stuff is asigning values like "let var = test ? valueWhenTrue : valueWhenFalse"

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

    For the number to string, wouldn't it be better to use myValue.toString() instead of concatenating a string to the number?

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

    What is your Wi-Fi speed Ed?

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

    The coolest teacher ever... :)

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

    Thank you ! I learned something new :)

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

    That magic trick was sick!!!!!

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

    its good .but number 9 you can use Object.entries(obj)=>conver object to arry

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

    OMG, I was always confused how to use the short if, and I understood it on the first try I of you saying it.

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

    Hi, with turnary is there any way to evaluate a single prompt() (instead of using a var) BUT more than 1 time?

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

    love you brother

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

    Dynamic Objects Are A Blessing!

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

    please keep your word about game development!! sooo looking forward to it explained by Ed

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

    It might be my Dunning Kreuger but I knew them all. Very reassuring though. Cheers.

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

    @ 0:25 when you switch speed settings from normal to 0.25, you will know all the magic secrets of Dev Ed

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

      thanks for pointing it out. I thought he stuffed his mouth and played it backwards. I was wrong.

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

      @@eric000 you're welcome 🎩

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

    Gooo for it!

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

    array to object was awesome 😆👌

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

    I was waiting for this!!!

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

    you're great dude!!

  • @AnonymousUser-vd2st
    @AnonymousUser-vd2st 5 років тому

    Thanks Ed! That was an interesting one!
    Well, noticed that your Spotify app is open always, what podcasts do you like to hear?

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

    that is soo good mate!

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

    you are awsome bro, These JS tricks are very helpful. I have started watching all of your video series... unemployed techlead , hahaha..... ultimate :)

  • @marcelnunez1658
    @marcelnunez1658 4 роки тому +6

    "I'm very excited for next year" bro...

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

    And yes to Tech Channel. Any excuse for more awesome DevEd.

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

    hey Ed .. help me out.
    so i m building a e-commerce web application and i m kinda stuck in a point . so how can i store my "ORDER ITEM" page information , to "CART" page and then after confirming what the customer ordered it goes to DB . i can work with DB but i m stuck at taking "order information" to my "cart " page ..and i dont to use any temp DB for it . i m new in web development and i not using any JS Framework . and suck at explaining stuff .. hope you getting what i m saying

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

    I think console.time("took miliseconds") and console.timeEnd("took miliseconds") would be more accurate instead performance.now() calculation.

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

    And I'm second! Bought and love the course you made Ed!

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

    Hi sir Dev Ed, can we combine HTML and CSS files in the SVG file? if we can. please guide me. I will be very thankful to you.

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

    Awesome Ed more like these pleaseeee thanksssss!

  • @its.arjun.s
    @its.arjun.s 5 років тому +9

    age > 50 ? console.log('Ok Boomer') : console.log('Ok Zoomer');

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

    I want to run JavaScript file placed within the script tag inside HTML file.
    I want to use VS code and google Chrome.
    Please list down the steps?
    Windows 10
    Thanks

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

    You were really really, really excited for this year lol

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

    I know all these stuff and have done them already!!! I'm good on my way!!!!

  • @AhmedMohamed-ff
    @AhmedMohamed-ff 5 років тому

    8:41 how you did this please? Like from one line to multiple lines in VS code

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

    Licking doors for a hobby got a whole new meaning now

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

    Starts @2:16

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

    Thank you sooo much for helping

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

    Unique Arrays & Dynamic Objects was amazing :O Woow!

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

    the introductory ad is lit ! XD

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

    the card trick was really nice

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

    I love this guy

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

    I love your videos Dev Ed =) One of the best web dev channel on UA-cam =) I would like to see your tech channel next year =)

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

    Excited for the next year ? 2020 you mean ?

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

    Awesome as usual !

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

    Knowledge blast with fun😄

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

    if(jumbo) then we go humbo 🤣🤣🤣

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

    What is your color theme? please

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

    [dynamic]: "sleep" i love it!!!

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

    I look forward to seeing a video about react hooks. I like the way you explained.

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

    What's your vscode theme?

  • @m.haydar.mosawi
    @m.haydar.mosawi 5 років тому

    I wish to u all success dev ed and thanks from heart ❤