Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Lesser Known Useful Javascript Features
Rating 5 V
delivi
post 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]);
Go to the top of the page
 
+Quote Post
trontron
post 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. sad.gif

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. tongue.gif
Go to the top of the page
 
+Quote Post
Forbez
post 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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Dreams For Halo 3 (or Halo Mods)(11)
  2. Javascript Slideshow Tutorial(3)
  3. Css And Javascript Combined For Dynamic Layout(9)
  4. Javascript Close Window(12)
  5. One Click Copy And Paste To Clipboard(5)
  6. Adding Rows & Columns In Html Table Using Javascript(1)
  7. Javascript : No Right Click Script !@(12)
  8. Hiding <div> Boxes With Javascript(8)
  9. Simple Scripts In Html And Javascript(7)
  10. The Power Of Java(14)
  11. Web Page Tree Menu: Style Sheet - Javascript(6)
  12. Learn Html Quick And Easy(14)
  13. Can I Make Dynamic Menu In Php(7)
  14. Flash And Javascript Interaction(1)
  15. Simple Javascript And Password System(7)
  1. Do You Close The Javascript?(4)
  2. 18 Features Windows Should Have (but Doesn't)(8)
  3. Document.write & Noscript Questions (javascript)(1)
  4. Java Vs Javascript(11)
  5. Make A Moderately-secure Password System Using Javascript(4)
  6. Windows 7 Now With Multitouch Features(0)
  7. Adjusting Rows/cols Of Frames In Frameset Using Javascript Is Not Working In Firefox 3 Is Not Working(4)
  8. Making A Picture Viewer Website(3)
  9. Javascript And Ajax For The Web, Sixth Edition Review(0)
  10. Creating A Floating Javascript Docking Menu(1)
  11. Browser Compatibility Problem With Firefox - Javascript + Css(3)
  12. Seeking Help With Javascript(1)
  13. Microsoft To Add Privacy Features To Ie8(2)


 



- Lo-Fi Version Time is now: 8th September 2008 - 07:34 AM