We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Help with JavaScript problem.

tincat
tincat Posts: 935 Forumite
Hi all, I'm really stuck on a problem as I can't seem to get it to sink in after re reading the textbook and stuff. Could anyone tell me if I'm on the right track with my answers (in blue).

Two variables have been set as follows:

var firstVar = 2;
var secondVar = 4;

The following lines of JS are executed in sequence, and you should write down value of firstVar and secondVar after each line is executed:

a)firstVar = secondVar
b)secondVar = firstVar
c)firstVar = firstVar + secondVar / 2

(a) firstVar = secondVar, so firstVar = 4.

(b) secondVar = firstVar, so firstVar = 4.


(c) firstVar = firstVar + secondVar/2.
=firstVar = 4 + (4/2)

=firstVar = 6

As far as I can understand, it doesn't matter what the declared values are, as you can specify them as something else and from that point on, the variable takes on the new specified value:confused:



I have no idea whether I'm correct so if anyone can explain it to me I'd be really grateful. Thanks
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 352.1K Banking & Borrowing
  • 253.6K Reduce Debt & Boost Income
  • 454.2K Spending & Discounts
  • 245.2K Work, Benefits & Business
  • 600.8K Mortgages, Homes & Bills
  • 177.5K Life & Family
  • 259K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16K Discuss & Feedback
  • 37.7K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.