Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
(new Array(1,2)==[1,2]) --> false why?
Old 04-12-2006, 12:50 PM (new Array(1,2)==[1,2]) --> false why?
gorilla's Avatar
Novice Talker

Posts: 7
Location: Hungary
Trades: 0
Hi, I'm not really experieced in javascript but I don't understand the difference between 'new Array(1,2)' and '[1,2]'.
Could someone explain me what the difference is?
gorilla is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-12-2006, 01:51 PM Re: (new Array(1,2)==[1,2]) --> false why?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
new Array(1,2) defines the array and it's size

array[1,2] is referencing an element in the array
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-12-2006, 02:07 PM Re: (new Array(1,2)==[1,2]) --> false why?
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
I think he's talking about literal notation, Chris.

Literal arrays are still array objects, so I'm kinda surprised they don't compare equally...
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 04-13-2006, 03:11 AM Re: (new Array(1,2)==[1,2]) --> false why?
Super Talker

Posts: 144
Trades: 0
same reason why

alert(Boolean([1, 2] == [1, 2]))

don't compare. they are both arrays but different objects.

whereas,

var arr = [1, 2];
var arr2 = arr;

alert(Boolean(arr == arr2)); <== returns true cause they reference the SAME object.
__________________
create.vibe

Please login or register to view this content. Registration is FREE
createvibe.com is offline
Reply With Quote
View Public Profile Visit createvibe.com's homepage!
 
Old 04-13-2006, 03:56 AM Re: (new Array(1,2)==[1,2]) --> false why?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I think he's talking about literal notation, Chris.
maybe I should have read the thread title as part of the question instead of just the body text.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-13-2006, 08:44 AM Re: (new Array(1,2)==[1,2]) --> false why?
gorilla's Avatar
Novice Talker

Posts: 7
Location: Hungary
Trades: 0
I see now.
One more dumb question:
Why did you use Boolean()?
Is alert(arr == arr2) different in some way?
gorilla is offline
Reply With Quote
View Public Profile
 
Old 04-13-2006, 08:29 PM Re: (new Array(1,2)==[1,2]) --> false why?
Super Talker

Posts: 144
Trades: 0
yes, using the == comparison operator will return a Boolean value, I just used Boolean to define things a bit clearer and keep it nice and tite. no big reason.
__________________
create.vibe

Please login or register to view this content. Registration is FREE
createvibe.com is offline
Reply With Quote
View Public Profile Visit createvibe.com's homepage!
 
Reply     « Reply to (new Array(1,2)==[1,2]) --> false why?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.58676 seconds with 12 queries