JavaScript void Operator

Поделиться
HTML-код
  • Опубликовано: 23 авг 2024
  • With the void ( ) operator in JavaScript you can execute an expression which returns nothing. It is similar to a function without a return statement except that it will only return "undefined".
    This provides us with the ability to inject code into the href attributes of anchor tags. Then users can click on the anchors to run the code without having the browser try to run the code and replace the current page.
    MDN reference for void : developer.mozi...

Комментарии • 25

  • @rotrose7531
    @rotrose7531 4 года назад +1

    Thank you very much for the explanation of this abstract subject, it may take some time for me to really understand it, but I will continue.

  • @alex_3D_websites
    @alex_3D_websites 7 месяцев назад

    Keep up the good work!

  • @chesterxp508
    @chesterxp508 2 года назад +1

    Another very cool tutorial !!!

  • @maximos118
    @maximos118 5 лет назад +3

    Nice microwave sounds ;) Still, very useful video. thanks!

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  5 лет назад +1

      yeah. Hard to keep the family out of the kitchen when I'm recording.

    • @maximos118
      @maximos118 5 лет назад

      @@SteveGriffith-Prof3ssorSt3v3 I've been programming for around 2 months now, got my html and css down. However, with the past couple of weeks learning JS I feel like... it hasn't clicked yet. Takes me ages to read code and get what's going on. Does that just come with time? Really want to actually understand what I'm doing rather than just blagging it when I write JS. Too much trial and error going on for my liking!

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  5 лет назад +2

      @@maximos118 Learning how to program does take time. There is no alternative to this. HTML and CSS are very visual things. You can see the screen change as you update things. With programming you are dealing with a lot of abstract concepts. It takes time and practice to get them straight in your head. You are learning a series of tools. Eventually you will have enough tools that you can build whole projects.
      2 months is nothing. I've been programming for 30+ years and I'm still learning.

    • @maximos118
      @maximos118 5 лет назад

      @@SteveGriffith-Prof3ssorSt3v3 I guess I'll keep going then! thanks again.

    • @laridot1942
      @laridot1942 Год назад

      @@maximos118 how are you doing now???

  • @AhmedAlaa-nf3yj
    @AhmedAlaa-nf3yj 3 года назад

    it's useful video thanks .

  • @oraz.
    @oraz. 9 месяцев назад

    Void does still return undefined,

  • @TheDogn
    @TheDogn 2 года назад

    3:03 After watching this tutorial I created an HTML file on my desktop and edited it to contain the following HTML:
    `click`
    Then I saved the file, loaded it in my web browser and clicked the link a few times.
    When I check the console the value 7 had been logged a few times... I guess that means the browser didn't take me anywhere? So I'm still not sure what was being demonstrated here.

  • @kuldeepkr5821
    @kuldeepkr5821 6 лет назад

    hi, can you elaborate the use-case of void you were talking about in the last of your video. How to use void operator to style any page without affecting other things.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  6 лет назад +1

      void is used to have functions treated like expressions. That means that they won't return a value. Sometimes you have a function that you don't need anything to be returned from. In cases like this, you can put void in front of the call to explicitly say that you don't need anything back.
      The most common use case was to put "void" in front of other code that you are running from inside an HTML anchor tag.
      javascript: is the protocol.
      myFunc( ) is the code that I want to run.
      void tells the browser to treat the function like an expression. Nothing(undefined) gets returned and the link doesn't go anywhere.
      If you are going to be altering styles with JavaScript you can do that in any function. You don't need to use void. A best practice would be to group all your style or DOM manipulations into functions on their own. Then you could call the functions with void in front of the call to explicitly say that nothing is expected back from the function. The return value will be undefined. Eg:
      function one( ){
      //do somethings
      //do more things
      void myFunctionToChangeStyles( );
      }
      Here I am calling my function and saying that I don't care about the result. Just pretend that it is an expression that has no return value.
      You can also put them in front of IIFEs (I have a video on these too) if the function is not returning anything.
      void function( ){
      //do something
      }( );
      This example is the same as:
      (function( ){
      //do something
      })( );

    • @rahuldubey5783
      @rahuldubey5783 4 года назад +1

      @@SteveGriffith-Prof3ssorSt3v3 thnx my doubt is clear after reading your reply

  • @romeojoseph766
    @romeojoseph766 Год назад

    is void still useful?

  • @ahsath
    @ahsath 6 лет назад

    Hi! do you have any videos about get and set?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  6 лет назад +1

      I'm currently working on videos for Object.defineProperty, the get and set within that method, as well as the new ES6 way of defining object methods and the get and set that come along with it.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  6 лет назад

      I have now posted one video about ES6 Object method syntax that includes getters and setters and another video about Object property methods including get and set.

    • @ahsath
      @ahsath 6 лет назад

      I already saw thoses

  • @yarik83men51
    @yarik83men51 4 года назад

    +++