Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Beginning JavaScript 5th Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning JavaScript 5th Edition
This is the forum to discuss the Wrox book Beginning JavaScript, 5th Edition by Jeremy McPeak; 978-1-118-90333-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript 5th Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 21st, 2016, 11:58 AM
Registered User
Points: 34, Level: 1
Points: 34, Level: 1 Points: 34, Level: 1 Points: 34, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2015
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
Default Chapter 2 - post increment /decrement not working

Hi, I've just started learning javascript with this promising book, but I got stuck in the increment and decrement part. The post increment /decrement not working with me:
HTML Code:
<script> 
var myFirstVariable=1;
var result; 
result=myFirstVariable++;
alert(result);
</script>
It shows the value without any change, that is 1
What am I missing here?
Thanks in advance
Reply With Quote
  #2 (permalink)  
Old May 23rd, 2016, 10:04 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

He assign the value to the variable "result" first.
Then he increment the variable "myFirstVariable".

If you want to verify, if the variable was incremented just write another alert function under the first one.

<script>
var myFirstVariable=1;
var result;
result=myFirstVariable++;
alert(result);
alert(myFirstVariable);
</script>

If you use the prefix increment:
result=++myFirstVariable;

It will increment first, and then assign the value to the variable.
Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
post increment and arrays situation in xslt scubin XSLT 1 July 25th, 2011 04:37 AM
overloading the increment and decrement operators(pg 540) esppeace BOOK: Ivor Horton's Beginning Visual C++ 2010 0 May 7th, 2011 09:24 AM
How to increment/decrement a parameter in XSL tclotworthy XSLT 2 February 9th, 2007 03:24 PM
POST method not working ganesh15 Beginning PHP 2 February 18th, 2006 07:35 AM
POST & GET not working on local VirtualHost Brian Campbell BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 October 27th, 2004 04:31 PM



All times are GMT -4. The time now is 06:02 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.