473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Variable initialization with curly braces

I've just been trying to de-construct the jQuery tooltop plugin in an
attempt to better my javascript coding and I've come across a question
google can't help me with.

What is the deal with initializing a variable like this?

Expand|Select|Wrap|Line Numbers
  1. var helper = {},
  2. // the current tooltipped element
  3. current,
  4. // the title of the current element, used for restoring
  5. title,
  6. // timeout id for delayed tooltips
  7. tID,
  8. // IE 5.5 or 6
  9. IE = $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent),
  10. // flag for mouse tracking
  11. track = false;
What are the first curly braces?

Thanks
Jun 28 '08 #1

✓ answered by Lasse Reichstein Nielsen

Nick S <nrsutton@gmail.comwrites:
What is the deal with initializing a variable like this?
>
var helper = {},
This declares the "helper" variable and assigns it a value that is
a new object.

...
What are the first curly braces?
The expression "{}" is an object literal expression that evaluates to
a new object with no extra properties. It's equivalent to
"new Object()".

/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'

4 4791
Nick S <nr******@gmail.comwrites:
What is the deal with initializing a variable like this?

var helper = {},
This declares the "helper" variable and assigns it a value that is
a new object.

...
What are the first curly braces?
The expression "{}" is an object literal expression that evaluates to
a new object with no extra properties. It's equivalent to
"new Object()".

/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 28 '08 #2
On Jun 28, 6:03*pm, Nick S <nrsut...@gmail.comwrote:
>
What is the deal with initializing a variable like this?

var helper = {},
(...)
What are the first curly braces?
It means "helper is an object".
It's the "literal notation" way of saying helper= new Object();

See :
<http://www.google.com/search?q=object+initialization+javascript>

--Jorge.
Jun 28 '08 #3
Jorge wrote:
On Jun 28, 6:03 pm, Nick S <nrsut...@gmail.comwrote:
>What is the deal with initializing a variable like this?

var helper = {},
(...)
What are the first curly braces?

It means "helper is an object".
No, it means helper currently *stores a reference* to a (native Object) object.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jun 28 '08 #4
On Jun 28, 6:17 pm, Lasse Reichstein Nielsen <l...@hotpop.comwrote:
Nick S <nrsut...@gmail.comwrites:
What is the deal with initializing a variable like this?
var helper = {},

This declares the "helper" variable and assigns it a value that is
a new object.

..
What are the first curly braces?

The expression "{}" is an object literal expression that evaluates to
a new object with no extra properties. It's equivalent to
"new Object()".

/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Thanks to everyone for your answers
Jun 28 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: STF | last post by:
While reading the C++ tutorial in this page: http://www.cplusplus.com/doc/tutorial/tut2-2.html I'm astonished to learn that we could omit curly brackets in function declaration for single...
7
by: Michael G | last post by:
I am a little surprised that the following that $x is visible outside of the scope in which it is (?)defined(?) (not sure if that is the correct term here). I am trying to find where in the php...
20
by: Petter Reinholdtsen | last post by:
Is the code fragment 'char a = ("a");' valid ANSI C? The problematic part is '("a")'. I am sure 'char a = "a";' is valid ANSI C, but I am more unsure if it is allowed to place () around the...
3
by: Primera | last post by:
I am trying to use the below to return different values of an int variable, but I seem to be running into scope issues as I cannot use the iSize variable outside of the foreach block. Any help is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.