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:
- Single Line Comments: Consist of a double forward slash (//) followed by the comment. For Example.
- Multiline Comments: Consist of one Forward Slash and an Asterisk (/*) and ends with one Asterisk and a Forward Slash (*/).
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:
- 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:
- 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:
- var hello = "hello";
- alert (hello);
The preceding code shows the value of hello variable in the alert box. But:
- var hello = "Hello";
- 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:
- Numbers = 10, 10.23
- Boolean = True/False
- 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:
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.