Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. using global variables

using global variables

Scheduled Pinned Locked Moved JavaScript
helpquestion
18 Posts 5 Posters 53 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Monjurul Habib

    Global variables have slow performance because they live in a highly-populated namespace. Not only are they stored along with many other user-defined quantities and JavaScript variables, the browser must also distinguish between global variables and properties of objects that are in the current context. The down side is this convenience slows down code that uses global variables. Sometimes global variables also have higher performance, like local function variables, if you declare them explicitly with the var keyword. An example is var d = document, instead of d = document, but it's not reliable. Mysterious behavior that works sometimes but not always is a danger sign, and I feel more comfortable using local function variables. More detail on Performance Optimizations for High Speed JavaScript

    N Offline
    N Offline
    Not Active
    wrote on last edited by
    #5

    Monjurul Habib wrote:

    local function variables, if you declare them explicitly with the var keyword.

    Then they wouldn't be global now would they?


    I know the language. I've read a book. - _Madmatt

    A M 2 Replies Last reply
    0
    • N Not Active

      Monjurul Habib wrote:

      local function variables, if you declare them explicitly with the var keyword.

      Then they wouldn't be global now would they?


      I know the language. I've read a book. - _Madmatt

      A Offline
      A Offline
      Ali Al Omairi Abu AlHassan
      wrote on last edited by
      #6

      OK, sir; ..., Shall you forgive him ?!!

      Help people,so poeple can help you.

      M 1 Reply Last reply
      0
      • M Monjurul Habib

        Global variables have slow performance because they live in a highly-populated namespace. Not only are they stored along with many other user-defined quantities and JavaScript variables, the browser must also distinguish between global variables and properties of objects that are in the current context. The down side is this convenience slows down code that uses global variables. Sometimes global variables also have higher performance, like local function variables, if you declare them explicitly with the var keyword. An example is var d = document, instead of d = document, but it's not reliable. Mysterious behavior that works sometimes but not always is a danger sign, and I feel more comfortable using local function variables. More detail on Performance Optimizations for High Speed JavaScript

        A Offline
        A Offline
        Ali Al Omairi Abu AlHassan
        wrote on last edited by
        #7

        Good Answer, Monjurul. 100 :rose: ;)

        Help people,so poeple can help you.

        M 1 Reply Last reply
        0
        • N Not Active

          Monjurul Habib wrote:

          local function variables, if you declare them explicitly with the var keyword.

          Then they wouldn't be global now would they?


          I know the language. I've read a book. - _Madmatt

          M Offline
          M Offline
          Monjurul Habib
          wrote on last edited by
          #8

          I think you will find your answer in the link..:thumbsup:

          N 1 Reply Last reply
          0
          • M Monjurul Habib

            I think you will find your answer in the link..:thumbsup:

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #9

            I didn't have a question. I do know though, do you know the difference between the meaning of local and global?


            I know the language. I've read a book. - _Madmatt

            M 1 Reply Last reply
            0
            • N Not Active

              I didn't have a question. I do know though, do you know the difference between the meaning of local and global?


              I know the language. I've read a book. - _Madmatt

              M Offline
              M Offline
              Monjurul Habib
              wrote on last edited by
              #10

              Sir, I am not a learned person like you. Can you please provide a link where you dump all of your knowledge specially on Javascript?? Thanks in advance.:thumbsup::thumbsup:

              N 1 Reply Last reply
              0
              • A Ali Al Omairi Abu AlHassan

                Good Answer, Monjurul. 100 :rose: ;)

                Help people,so poeple can help you.

                M Offline
                M Offline
                Monjurul Habib
                wrote on last edited by
                #11

                Thanx :)

                1 Reply Last reply
                0
                • M Monjurul Habib

                  Sir, I am not a learned person like you. Can you please provide a link where you dump all of your knowledge specially on Javascript?? Thanks in advance.:thumbsup::thumbsup:

                  N Offline
                  N Offline
                  Not Active
                  wrote on last edited by
                  #12

                  I store it here[^]


                  I know the language. I've read a book. - _Madmatt

                  M 1 Reply Last reply
                  0
                  • N Not Active

                    I store it here[^]


                    I know the language. I've read a book. - _Madmatt

                    M Offline
                    M Offline
                    Monjurul Habib
                    wrote on last edited by
                    #13

                    great link. ;) and may b you forgot to share this link

                    modified on Saturday, March 5, 2011 6:11 PM

                    P 1 Reply Last reply
                    0
                    • A Ali Al Omairi Abu AlHassan

                      OK, sir; ..., Shall you forgive him ?!!

                      Help people,so poeple can help you.

                      M Offline
                      M Offline
                      Monjurul Habib
                      wrote on last edited by
                      #14

                      I really like your comment "Help people,so poeple can help you."

                      A 1 Reply Last reply
                      0
                      • M Monjurul Habib

                        I really like your comment "Help people,so poeple can help you."

                        A Offline
                        A Offline
                        Ali Al Omairi Abu AlHassan
                        wrote on last edited by
                        #15

                        over my head, sir.:thumbsup:

                        Help people,so poeple can help you.

                        1 Reply Last reply
                        0
                        • M Monjurul Habib

                          great link. ;) and may b you forgot to share this link

                          modified on Saturday, March 5, 2011 6:11 PM

                          P Offline
                          P Offline
                          Pete OHanlon
                          wrote on last edited by
                          #16

                          Stop it, the pair of you. There is no excuse for this form of behaviour in the forums. Please refrain from these attacks - they are not clever.

                          I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                          Forgive your enemies - it messes with their heads

                          My blog | My articles | MoXAML PowerToys | Onyx

                          M 1 Reply Last reply
                          0
                          • P Pete OHanlon

                            Stop it, the pair of you. There is no excuse for this form of behaviour in the forums. Please refrain from these attacks - they are not clever.

                            I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                            Forgive your enemies - it messes with their heads

                            My blog | My articles | MoXAML PowerToys | Onyx

                            M Offline
                            M Offline
                            Monjurul Habib
                            wrote on last edited by
                            #17

                            apologize

                            A 1 Reply Last reply
                            0
                            • M Monjurul Habib

                              apologize

                              A Offline
                              A Offline
                              Ali Al Omairi Abu AlHassan
                              wrote on last edited by
                              #18

                              over my head, Sir

                              Help people,so poeple can help you.

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups