|
|
|
|
![]() ![]() |
Jul 3 2008, 10:39 PM
Post
#1
|
|
|
Trap Grand Marshal Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 1,308 Joined: 11-January 06 From: Chennai, India Member No.: 16,932 |
Variables
Javascript assigns every variable a type which changes as we assign different values to the variable. We can get the type of a variable using the 'typeof' operator. For eg., CODE var hello = "Welcome to Trap17"; var year = 2008; alert(typeof hello ); alert(typeof year ); The above lines will output the type of the first variable 'hello' as String and the second variable 'year' as Number. The types of Javascript variables are Boolean, Function, Number, Object and String. A variable with no explicitly assigned value has a value 'undefined'. '===' Operator The === Operator (with three equals signs), always returns 'false ' if two operands are of different types and performs the operation of '==' operator if they are of same type. So the '===' is used to strictly compare two operands that are of same type. CODE var a = 123; //Number var b = "123"; //String alert( a == b ); alert( a === b ); the first output returns true as it just compares the value and ignores the tpe of the variables, whereas the second expression outputs 'false' as the two variables are of different types. for-in Javascript has a for similar to the one found in other programming languages. It also has a variant of the 'for' that can be used to iterate over the properties of an object or to iterate over arrays. CODE var rainbow = [ "Violet" , "Indigo" , "Blue" , "Green" , "Yellow" , "Orange" , "Red" ];
for ( var color in rainbow ) alert(colors[color]); |
|
|
|
Jul 8 2008, 07:37 AM
Post
#2
|
|
|
Newbie [Level 1] ![]() Group: [HOSTED] Posts: 16 Joined: 28-May 08 From: Void of space and beyond Member No.: 62,801 |
Wow! Thanks for the enlightenment. I have used JavaScript before but there are just so many operators which provide quite a huge number of possibilities and can dramatically increase the functionality of your website. However quite a lot of people don't trust Java since it can be used in wrong and harmful ways.
Nonetheless, I recommend that people check out the W3Schools website to help learn java as it is an well crafted resource for beginners. After you start to get the hang of it you'll wish that you learned it earlier. |
|
|
|
Jul 9 2008, 02:29 PM
Post
#3
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 607 Joined: 13-December 06 Member No.: 35,271 |
Yeah, this is a good tutorial. I also agree, w3schools is a great resource for learning more about javascript. Nevertheless, this tutorial is so really good.
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 8th September 2008 - 07:34 AM |