Basics of JavaScript

Comments in JavaScript

 
If you are familier with comments in C#, then its easy for you to understand. 
 
There are two types of comments in JavaScript:
  1. Single Line Comments- Consist of a double forward slash (//) followed by the comment. For Example.
     
  2. Multiline Comments- Consist of one Forward Slash and an Asterisk (/*) and ends with one Asterisk and a Forward Slash (*/).
    1. //alert('Welcome to the first class of C# with JavaScript');      
    2. /*alert('Welcome to the first class of C# with JavaScript');*/    

Case Sensitivity

 
This client-side scripting language is case sensitive in nature like that of C# and others. All the variable names, keywords, methods and so on are case sensitive.
 
For example
  1. alert('Welcome to the first class of C# with JavaScript');    
The preceding code works as usual and shows an alert box on the screen. But:
  1. Alert('Welcome to the first class of C# with JavaScript');    
This code will not show anything in the browser window. You can also check for errors by pressing the F12 key in the browser and the Elements window will open and display the error.
 
The same is the case of a variable as follows:
  1. var hello = "hello";      
  2. alert (hello);    
The preceding code shows the value of hello variable in the alert box. But:
  1. var hello = "Hello";      
  2. alert (Hello);     
This code will not show anything because the variable name is case sensitive. So, we are changing the first letter of the variable. The error can be seen using the F12 key in the browser window.
 

Data Types in JavaScript

 
There are the 3 major types of variables in JavaScript: 
  1. Numbers = 10, 10.23  
  2. Boolean = True/False  
  3. String = 'Welcome',"Welcome" 
The data types are dynamically converted at the runtime depending on the value stored in them.
 
A variable is declared using a "var" keyword as follows:
  1. var a = 10;    
But the data type is not specified because it is decided by the script at runtime depending upon the value stored in it. Every type of variable is declared in the same way, whether it stores a string, or a boolean or a numerical value.
 
I will write more articles on JavaScript. Keep reading.