Skip to content

Chapter 5 bookmarklet_launcher.js #101

Description

@AmirShehzadDev

Can anyone please help me understand its code?

(function(){ if (window.myBookmarklet !== undefined){ myBookmarklet(); } else { document.body.appendChild(document.createElement('script')).src='https://127.0.0.1:8000/static/js/bookmarklet.js?r='+Math.floor(Math.random()*99999999999999999999); } })();

  1. Why we need to put function inside parenthesis? (function.....)()
  2. How browser executes the code when we put javascript tag? JavaScript:(function.....)()
  3. what is this function myBookmarklet() and when if statement will be actually executed? How will window object will have myBookmarklet property?

Please share any resources as well. Thanks a lot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions