- The alliance of Netscape and Sun Microsystems did not use Java in the browser, because it was not suitable for that purpose. Why do you think Java was not suitable to be embedded in a browser?
Java was too heavy and clumsy.
- When parsing a String into a number using the parseInt() method, we are advised to always provide the radix. Why is it so strongly recommended?
The radix specifies what numerical system is used. If not specified, it will be decided by JavaScript itself, and that can cause unexpected results.
- What is a type, and why do you think types are useful in writing programs?
Really hard to put words on this one. The type can be for example: string, numeric or Boolean. JavaScript will handle the information differently depending on the type.
It is useful because a wide range of options gets available. Some events may only be executed if another event returns true or false, or if the result is equal, less than or greater than a value.
Control is the word.
Basically a type defines a universe within which certain things are possible by pressing buttons. The type also defines those buttons.
Coming back to programming, String is a type which has certain functions. These functions are the buttons, and what they do is the effect.
Comment from Parag:
Think of type as something which offers certain buttons and actions when you press those buttons. So a type could be a DvdPlayer, in which case you will have buttons to start, stop, pause, forward, rewind, etc. If the type is a car then you will have start, stop, change_gear, etc.Basically a type defines a universe within which certain things are possible by pressing buttons. The type also defines those buttons.
Coming back to programming, String is a type which has certain functions. These functions are the buttons, and what they do is the effect.
- Why do we lose precision when performing operations with decimal numbers in JavaScript? Can you think of a few implications of why this would be a problem?
Document.write(0.1+0.2) gave the result: 0.30000000000000004
While
a=0.1;
b=0.2;
c=a*100;
d=b*100;
e=c+d;
f=e/100;
document.write(f)
gave the result: 0.3
I didn’t manage to get 0.3 as the result without multiplying a and b with 100 separately. (a+b)*100 did not give the expected result.
- Do you understand why the following operation produces the given result 115 * 4 - 4 + 88 / 2 = 500
115*4=460
460-4=456
460-4=456
88/2=44
456+44=500
* and / have higher precedence and is therefore calculated before. This is why the result is 500 and not 272. (115+4)-4+(88/2) = 500
456+44=500
* and / have higher precedence and is therefore calculated before. This is why the result is 500 and not 272. (115+4)-4+(88/2) = 500
- What does typeof 4.5 do, and why does typeof (typeof 4.5) return "string" ?
typeof 4.5 returns: “number” just as typeof (4.5) would do.
But why typeof (typeof 4.5) return "string", that I can’t find the answer for. Could it be that the result of typeof 4.5 is returned as a string?
But why typeof (typeof 4.5) return "string", that I can’t find the answer for. Could it be that the result of typeof 4.5 is returned as a string?
glenn.hellquist@gmail.com
webbkraft.com
Nice answers.
SvaraRaderaThink of type as something which offers certain buttons and actions when you press those buttons. So a type could be a DvdPlayer, in which case you will have buttons to start, stop, pause, forward, rewind, etc. If the type is a car then you will have start, stop, change_gear, etc.
Basically a type defines a universe within which certain things are possible by pressing buttons. The type also defines those buttons.
Coming back to programming, String is a type which has certain functions. These functions are the buttons, and what they do is the effect.