Introduction
This article explains some basic concepts of JavaScript used in Web Applications, like comments, objects, etc.
Before reading this article, I highly recommend reading the previous parts,
Comments in JavaScript
In JavaScript, comments are used for skipping that statement from execution; using comments, you make code more readable and understandable for anyone. Code functionality is clearer using comments. The following comments are used in JavaScript:
- Single Line Comment
- Multi-line comment
Single Line Comment in JavaScript
When you want to comment out a single statement, then a single-line comment is used; it starts with "//". JavaScript ignores this line. Using this, you can comment out an entire line.
The following example uses a single-line comment to explain the code,
<!DOCTYPE html>
<html>
<title>JavaScript Comments</title>
<head></head>
<body>
<script language="javascript">
//Single line comment
//Addition of two numbers
var a = 25;
var b = 75;
var c = a + b; //addition of a and b is store in c variable
document.write("Addition of " + a + " and " + b + " is " + c);
</script>
</body>
</html>
Output
Addition of 25 and 75 is 100
Multi-line Comment in JavaScript
A multi-line comment is used with a group or code block that you want to comment out. A multi-line comment starts with /* and ends with */. JavaScript skips the code block between this.
In the following example, a group of statements is commented out using multi-line comments.
<!DOCTYPE html>
<html>
<title>JavaScript Comments</title>
<head></head>
<body>
<script language="javascript">
/*
var a = 25;
var b = 75;
var c = a + b; //addition of a and b is store in c variable
document.write("Addition of " + a + " and " + b + " is " + c);
*/
function Print() {
document.write("Example of Multi-line Comments in JavaScript");
}
Print();
</script>
</body>
</html>
Output
Example of Multi-line Comments in JavaScript
Objects in JavaScript
An object is a thing, just like things in the real world. Objects are a way to organize variables. In the web browser, objects include the browser window, forms and buttons, and so on. (For example, cars, books, dogs, and money.)
Properties and Methods in JavaScript
Every object has its properties and methods. Properties define the characteristics of an object. (For example, color, name, length.) Methods that can be done on objects.
(For example, alert, confirm, and open.)
The following is the syntax of properties:
objectName.propName or objectName[“property”]
The following is the syntax of methods,
methodName : function () { Statements; }
Example
The following demo example explains the concept of objects, properties, and methods. In this example, an object is created named "employee". It has the property's name and city. Creating the method for this object employee and call.
<!DOCTYPE html>
<html>
<title>JavaScript Objects</title>
<head></head>
<body>
<script language="javascript">
var employee = new Object(); //Creating an object
//Assigning properties to an object 'employee'
employee.name = "Jeetendra";
employee.city = "Pune";
//Assigning method to an object 'employee'
employee.info = function () {
document.write("Name : " + this.name + " City : " + this.city);
}
//calling the method
employee.info();
</script>
</body>
</html> 
Sam HobbsPosted Nov 28, 2014, 2:40 PM
Thank you Jeetendra. I just want to say that in addition to causing statements to be not executed, comments can also be used for comments.