Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Beginning JavaScript 5th Edition
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 21st, 2016, 11:58 AM
Registered User
 
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
 
Old May 23rd, 2016, 10:04 AM
Registered User
 
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.





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 04:24 PM
POST method not working ganesh15 Beginning PHP 2 February 18th, 2006 08: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.