Jump to content
xisto Community
Sign in to follow this  
delivi

Lesser Known Useful Javascript Features

Recommended Posts

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.,

var hello = "Welcome to Xisto";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.

 

var a = 123;	 //Numbervar b = "123";  //Stringalert( 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.

 

var rainbow = [ "Violet" , "Indigo" , "Blue" , "Green" , "Yellow" , "Orange" , "Red" ];for ( var color in rainbow )   alert(colors[color]);

Share this post


Link to post
Share on other sites

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. ;)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.