Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7033229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:02:16+00:00 2026-05-28T01:02:16+00:00

this is just a simple performance question, helping me understand the javascript engine. for

  • 0

this is just a simple performance question, helping me understand the javascript engine.
for this I’m was wondering, what is faster: declaring multiple variables for certain values or using one object containing multiple values.

example:

var x = 15;
var y = 300;

vs.

var sizes = { x: 15, y: 300 };

this is just a very simple example, could of course differ in a real project.
does this even matter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:02:17+00:00Added an answer on May 28, 2026 at 1:02 am

    A complete answer for that question would be really long. So I’ll try to explain a few things only. First, maybe most important fact, even if you declare a variable with var, it depends where you do that. In a global scope, you implicitly would also write that variable in an object, most browsers call it window. So for instance

    // global scope
    var x = 15;
    
    console.log( window.x ); // 15
    

    If we do the same thing within the context of a function things change. Within the context of a function, we would write that variable name into its such called ‘Activation Object’. That is, an internal object which the js engine handles for you. All formal parameters, function declarations and variables are stored there.

    Now to answer your actual question: Within the context of a function, its always the fastest possible access to have variables declared with var. This again is not necesarrily true if we are in the global context. The global object is very huge and its not really fast to access anything within.

    If we store things within an object, its still very fast, but not as fast as variables declared by var. Especially the access times do increase. But nonetheless, we are talking about micro and nanoseconds here (in modern browser implementations). Old’ish browsers, especially IE6+7 have huge performance penalties when accessing object properties.

    If you are really interested in stuff like this, I highyl recommend the book ‘High Performance Javascript‘ by Nicholas C. Zakas. He measured lots of different techniques to access and store data in ECMAscript for you.

    Again, performance differences for object lookups and variables declared by var is almost not measureable in modern browsers. Old’ish Browsers like FF3 or IE6 do show a fundamental slow performance for object lookups/access.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is hopefully just a simple question involving performance optimizations when it comes to
This is just a simple question. I've been reading the source of something which
[see later answer for more] I think this is just a simple rails question,
This might be a simple question but I'm just picking this up so please
I just want to design this very simple website. Basically there are multiple pages
This should be a simple question, but I just can't recall the relevant API.
This is just a simple question. I'm currently using Mozilla's Rhino to develop a
I have just run a very simple JavaScript performance test (don't ask why). The
Best explained with code I think, this is just a simple example: public class
Below just a simple race between 2 button in 2 threads, and this will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.