473,462 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

easy debug question?

I know this has to be easy, but I can't seem to figure it out. I'm debuggin' someone elses code...

x="hello";
+x+"world"

....and I don't get it! What does the "+x+"world" do? If I alert(x) the only thing that comes out is "hello". I also wondered why it doesn't error without the ";" at the end of the line.

I appreciate the help...

-Bruce Duncan
**** feeling dumb today...just wait till tomorrow....****
Jul 23 '05 #1
3 1134
In article <10*************@corp.supernews.com>,
bruce~w~duncan@~hotmail.com enlightened us with...
I know this has to be easy, but I can't seem to figure it out. I'm debuggin' someone elses code...

x="hello";
+x+"world"

...and I don't get it! What does the "+x+"world" do?
If I alert(x) the only thing that comes out is "hello".
I also wondered why it doesn't error without the ";" at the end of the line.

I appreciate the help...

Um, I don't think the semi-colon should be there. I think it was
supposed to be one line. Or the second line should have been
x=x+" world";
That code doesn't look like it is valid. Note that browsers don't
necessarily show you errors.

Semi-colons are not required at the end of the line in JS; they are
recommended for clarity if the end of the line is also the end of the
statement.
(the above is a bit simplified)

--
--
~kaeli~
You feel stuck with your debt if you can't budge it.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <10*************@corp.supernews.com>,
bruce~w~duncan@~hotmail.com enlightened us with...
I know this has to be easy, but I can't seem to figure it out. I'm debuggin' someone elses code...
x="hello";
+x+"world"

...and I don't get it! What does the "+x+"world" do?
If I alert(x) the only thing that comes out is "hello".
I also wondered why it doesn't error without the ";" at the end of the line.
I appreciate the help...

Um, I don't think the semi-colon should be there. I think it was
supposed to be one line. Or the second line should have been
x=x+" world";
That code doesn't look like it is valid. Note that browsers don't
necessarily show you errors.

Semi-colons are not required at the end of the line in JS; they are
recommended for clarity if the end of the line is also the end of the
statement.
(the above is a bit simplified)

--
--
~kaeli~
You feel stuck with your debt if you can't budge it.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace


I believe you are correct Kaeli!
I was hoping that it wasn't some wierd way of assigning vars that I just
hadn't seen before. My mind isn't working so great this morning...thanks
for the response...it helped open my eyes a bit.

-Bruce Duncan

Jul 23 '05 #3
Bruce Duncan wrote:
I know this has to be easy, but I can't seem to figure it out.
I'm debuggin' someone elses code... x="hello";
+x+"world"...and I don't get it! What does the "+x+"world"
do? If I alert(x) the only thing that comes out is "hello". I
also wondered why it doesn't error without the ";" at the end
of the line. I appreciate the help... -Bruce Duncan**** feeling
dumb today...just wait till tomorrow....****


The +x + "world" doesn't do anything. Well, actually, it applies
the unary operator to the value of x (returning zero). toString()
is implicitly called on that zero and it is concatentated to the
word "world". The result is a string "0world". However, that
value is never assigned to anything, so it is discarded almost
immediately.

Semi-colons are only required in Javascript when multiple
statements appear on the same line, however, it's a good habit to
put them at the end of every non-block.

As for why this isn't doing what you want, I think what you want
is:

var x = "hello";
x = x + " world"; // notice x + " world" is assigned back to x
// you can also use x += " world";
alert(x);

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available
at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #4

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

Similar topics

5
by: Kelvin Chu | last post by:
Hi Group, (Using php5 on apache1) is there an equivalent of .= in PHP? I'm making a program and I have lots of debug statements being added using $debug = $debug . "some text"
1
by: glaserp | last post by:
Hi, I am developing a Windows application with C# in Visual Stuio .NET. My application references three assemblies that are developed in another project. I have added these assemblies as...
8
by: Davy | last post by:
Hi all, I use VC and gcc/gdb to compile and debug C/C++ files. But I found some of the debug version of the compiled files are too large to be run in a small RAM. Can I compile C/C++ Debug...
4
by: emma middlebrook | last post by:
I have a question regarding asserting ... here's some code: string GetAssertMessage() { ... prepare a message string and return it... } void SomeMethod() { ...
6
by: Nick | last post by:
Hi, simple question XmlDocument doc = new XmlDocument(); FileStream file = new FileStream (PathAndFileName,FileMode.Open,FileAccess.Read,FileShare.ReadWrite); doc.Load(file); should I now...
4
by: Stephen Miller | last post by:
Hi, I am running v1.1.4322 on Win2K server and unable to debug a ASP.Net application running locally, using a full URL (ie www.mysite.com). When I hit F5, I get the following error message: ...
2
by: Dan | last post by:
Hi I need to execute a line of code when debugging and another when in release without having to manually comment and uncomment. Can anyone tell me the switch syntax in c# in visual studio? thanls
6
by: Andrew Rowley | last post by:
I am having trouble getting debug and release builds to work properly with project references using C++ .NET and Visual Studio 2003. I created a test solution, with a basic Windows form C++...
1
by: samadams_2006 | last post by:
Hello, I haven't done much programming in .asp and was wondering if someone could provide me with some sample code to do the following task... I have a Web Service called: ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.