Some JavaScript basics

Learn javaScript

Learn javaScript

I recently started watching Essentials of javaScript by DoriSmith @ Lynda.Com, It’s very interesting, easy to understand and helpful like many other video tutorials at Lynda.Com.

Video tutorials are very easy to follow, productive and easy to grasp. The only problem I find with video tutorials is, when you get stuck or have some doubt few days after watching the tutorial, it’s hard to refer back. So, its always good to prepare some notes of important points which you can refer back easily. I’m going to share my notes here as I go along, I hope you find it use full.

javaScript is often confused with JAVA, both of them are entirely different. javaScript was invented by Netscape and was initially called LiveScript. The :re was a time when there was a huge buzz about JAVA in tech world, so netscape decided to catch some of that buzz and renamed LiveScript as javaScript, If you were thinking that javaScript and JAVA are same, then netscape was successful in their bushiness strategy :P

javaScript is a scripting language which adds interactivity to the webpages. A scripting language is something which does not require a compiler or a fancy development environment. javaScript is interpreted and run by browsers.

  • javaScript can not talk to database.
  • It can not write to files, expect for cookies. So you can not maintain counters with javaScript.

Variables in javaScript

Variables are objects that you create, you initialize a variable b saying var then followed by the name and then the value (value part is optional). In javaScript you need nor explicitly say the type of variable like you do in C or C++, It’s done automatically with javaScript.

Variable names can not start with numbers, they can not contain space and dashes(-), usually variable names are started with a lower case letter and the next word is appended by capitalizing the first letter, like I’m doing for javaScript in this document.

Some Correct variable names
userName,UserName, username,
Wrong variable names

1user, user-name,user name

Variable names like var1,var2 are correct but not advised to be used as when you look back the back after some days you may not understand what var1 or var2 means. It’s advised that you use some meaning full user names like catName, place,gender.

/*Declaring variables in javaScript */
var myName;
var myName=Satish; //Declaring while initializing

In the above code the lines 2 and 3 are together equivalent to line 4.

var string="2"+"3"; //String has the value 23, not 5
var string="cat"+5; //javaScript converts 5 in to string and adds it to cat, string has the value cat5
var myVar=10;
var anotherString=myVar+"cat"; //anotherString has the value 10cat

In my next post I will write about operators and events, stay tuned.

Buy Essentials of javaScript by DoriSmith

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>