iv been trying to get a basic idea for the past coupla years now..
could you explain how you got 25?
Code:
var Max =4, Answer = 10;
var Value = new Array(Max);
for (i=0;i<=Max;i++)
Value[i]=i+1;
for (i=0;i<=Max;i++)
Answer +=Value[i];
alert (Answer);
It isn't that much hard. first you need to know what is a variable.
variable is a container which lays in the system memory (RAM) and store values in binary form. it has an unique address which is used by the application to identify that particular variable.
so in this phase what you do is
declare a variable which means actually make a variable in the system memory and its name is "MAX" though its name is max actually it doesn't have a name(the name is for the programmer so programmer can give it a meaningful name rather than numbers(address) so programers can easily program) it has an address in the memory and value 4 is stored by the application in that memory slot.
THIS IS THE BASIC. if you wanna know more advance the picture might be a bit different. cause there are datatypes though JavaScript doesn't have datatypes when you declare a variable the application defines the datatype of that variable depend in the value passes(assign) to that variable.
so if you pass 3 to any variable the application defines that variable's datatype as integer. integer is normally 32bit.
(1 Byte is equal to = 8 bits) so in the memory 32/8 = 4 bytes of values it can hold.
now take this example you pass 4 value to the MAX variable.
so the application identifies automatically the datatype of the MAX variable and stores the value 4 inside the MAX variable.
the numbers or everything represents in the system memory as BINARY.
so ONE character takes 1 byte (if it's ASCII if it's UNICODE 2 bytes) (this is for characters NOT numbers) when it comes to numbers the picture is different.
convert 4 to binary then u can get this 0100.
in 32bit you can go to MAX
0000 0000 0000 0000 0000 0000 0000 0000
this is minimum value that you can store in a 32bit (integer) variable in this case MAX variable. the MAX value is
0111 1111 1111 1111 1111 1111 1111 1111 (BINARY)
which is equal to 2147483647 (in DECIMAL)
and this the Maximum VALUE you can hold in the MAX variable.
the reason for keeping the first value as 0 cause it's for identifying whether this number is a POSITIVE or a NEGATIVE VALUE.
if it's negative first 0 is 1, if it's a positive value the first value is 0.
Now tell me do u understand so far? if u have any issue then let me know.