Friday, 10 November 2017

Why the JavaScript can be a case sensitive

In JavaScript, the case sensitivity does not just apply to variable names but also to JavaScript keywords, event handlers, and object properties or methods.

Example: Example to say JavaScript is a case senstive
<! DOCTYPE html> 
<html> 
<head> 
<title>Javascript Case Sensitivity</title> 
</head> 
<script type="text/javascript"> 
var customerName = "Peter write"; 
var CustomerName = "Charlie S write"; 
var CUSTOMERNAME = "Tom write"; 
document.write(customerName + '</br>' + CustomerName+ '</br>' + CUSTOMERNAME); 
</script> 
<body> 
</body> 
</html>

E.g. Description

Why Javascript is a case-sensitive:
JavaScript is a case-sensitive language.This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters. The while keyword, for example, must be typed "while", not "While" or "WHILE". Similarly, online, Online, OnLine, and ONLINE are four distinct variable names.
In JavaScript, the case sensitivity does not just apply to variable names but also to JavaScript keywords, event handlers, and object properties or methods. Keywords in JavaScript are all lowercase, for example, while, for, if, else, and so on. On the other hand, methods (properties) use "camel-back" naming convention ( the first word is in lowercase and each successive first letter of each word is capitalized), for example, toArray(), lastModified(), and so on.

READMORE


General Information about Method and Property attributes in JS using OOP

Properties are variables contained in the class.In every instance of the object has those properties. Properties are set in the constructor of the class so that they are created on each instance.

Example: Code Snippet for Method and Property Attibute
//Example for Method attibute
<script type="text/javascript">
var Person = function (firstName) {
this.firstName = firstName;
console.log('Person instantiated');
};
var person1 = new Person('Allen boult');
var person2 = new Person('Chris Jordan');

// Show the firstName properties of the objects
console.log('person1 is ' + person1.firstName); // logs "person1 is Allen boult".
console.log('person2 is ' + person2.firstName); // logs "person2 is Chris Jordan".
//Example for Property attibute
//Define the class Car
function Car(speed) {
alert("Class CAR is Instantiated");
this.speed = speed;
}
Car.prototype.speed= 'Car Speed';
Car.prototype.setSpeed = function(speed) {
this.speed = speed;
alert("Gradually Car speed changed");
}

var car1 = new Car(40);
var car2 = new Car(70);

car1.setSpeed(130);
car2.setSpeed(140);

</script>

E.g. Description

The Property (Object attribute):
Properties are variables contained in the class. In every instance of the object has those properties. Properties are set in the constructor of the class so that they are created on each instance.
The keyword this refers to the current object, lets you work with properties from within the class. Accessing a property outside of the class is done with the syntax: InstanceName.Property, just like in C++, Java, and several other programming languages.
From the above example mentioned we define the firstNameproperty for the Person class at Instantiation in which we use the variables of person1 and person2.output displayed on the screen as follows
"person1 is Allen Bolt".
"person2 is Chris Jordan".
Methods:
Methods are same as function and they are defined like functions. To define a method, assign a function to a named property of the class's prototype property. Later, you can call the method on the object by the same name as you assigned the function to.
To define methods in a Class, all you have to do is just define an attribute and assign a function to it.From the above example mentioned we defined a method setSpeed() for the class Car. When the speed is changed compare to car1 it alerts the message as "Gradually Car Speed Changed".

READMORE

How Can String Datatype Executed in Javascript

JavaScript string data type represent textual data surrounding to single / double quotes. Each character is represented as an element that occupies the position of that string.

Example: Simple Code for String Datatype
<! DOCTYPE html>
<html>
<body>
<p id="string"></p>
<script>
var carName1 = "Etios";
var carName2 = 'RangeRover';
var answer1 = "It's alright";
var answer2 = "My self 'Matt Henry'";
var answer3 = 'He is called "Robert"';
document.getElementById("string").innerHTML =
carName1 + "<br>" +
carName2 + "<br>" +
answer1 + "<br>" +
answer2 + "<br>" +
answer3;
</script>
</body>
</html>

E.g. Description

Whatever quote you use to represent the string, but you should take care that quote can't repeat in string statement.
Unlike in languages like C, JavaScript strings are immutable. This means that once a string is created, it is not possible to modify it. However, it is still possible to create another string based on an operation on the original string.
Use strings for textual data. When representing complex data, parse strings and use the appropriate abstraction.
Above example describes you to execute the string datatype using the keyword called "var", assigned the function class names as a car with respective to the functioning of that.The getElementById() method returns the element that has the ID attribute with the specified value. We assigned the content in single and double quotes which we wanted to display on the output screen.

READMORE


What are Different Datatypes in JavaScript

JavaScript is a dynamic typed (or termed as Loosely Typed) scripting language which means that same variable can be assigned data of different types.

Description

Javascript Datatypes:

JavaScript is a dynamic typed (or termed as Loosely Typed) scripting language which means that same variable can be assigned data of different types. JavaScript provides different data types to hold different types of values. There are two types of data types in JavaScript.
Primary Data Types (Primitive)
  1. String
  2. Number
  3. Boolean
Composite Data Types (reference)
  1. Object
  2. Array
  3. Special Data Types
  4. Null
  5. Undefined
String: A strings of any characters enclosed in quotes is a string primitive.
Number: A number by itself is a number primitive, all numbers in JavaScript are 64-bit floating point numbers.
Boolean: It will store Variables or expressions which are either true or false.
Object: A collections of properties and methods. In Javascript, anything that is not a primitive is an Object.
Arrays: Arrays are regular objects, both objects and arrays can have properties and methods.
Null: It has only one value in JavaScript: null.
Undefined: It treated as a variable that has been declared, but has never had a value assigned to it.

READMORE

Wednesday, 8 November 2017

What are Different Datatypes in JavaScript

JavaScript is a dynamic typed (or termed as Loosely Typed) scripting language which means that same variable can be assigned data of different types.

Description

Javascript Datatypes:

JavaScript is a dynamic typed (or termed as Loosely Typed) scripting language which means that same variable can be assigned data of different types. JavaScript provides different data types to hold different types of values. There are two types of data types in JavaScript.
Primary Data Types (Primitive)
  1. String
  2. Number
  3. Boolean
Composite Data Types (reference)
  1. Object
  2. Array
  3. Special Data Types
  4. Null
  5. Undefined
String: A strings of any characters enclosed in quotes is a string primitive.
Number: A number by itself is a number primitive, all numbers in JavaScript are 64-bit floating point numbers.
Boolean: It will store Variables or expressions which are either true or false.
Object: A collections of properties and methods. In Javascript, anything that is not a primitive is an Object.
Arrays: Arrays are regular objects, both objects and arrays can have properties and methods.
Null: It has only one value in JavaScript: null.
Undefined: It treated as a variable that has been declared, but has never had a value assigned to it.

READMORE

How Can String Datatype Executed in Javascript

JavaScript string data type represent textual data surrounding to single / double quotes. Each character is represented as an element that occupies the position of that string.

Example: Simple Code for String Datatype
<! DOCTYPE html>
<html>
<body>
<p id="string"></p>
<script>
var carName1 = "Etios";
var carName2 = 'RangeRover';
var answer1 = "It's alright";
var answer2 = "My self 'Matt Henry'";
var answer3 = 'He is called "Robert"';
document.getElementById("string").innerHTML =
carName1 + "<br>" +
carName2 + "<br>" +
answer1 + "<br>" +
answer2 + "<br>" +
answer3;
</script>
</body>
</html>

E.g. Description

Whatever quote you use to represent the string, but you should take care that quote can't repeat in string statement.
Unlike in languages like C, JavaScript strings are immutable. This means that once a string is created, it is not possible to modify it. However, it is still possible to create another string based on an operation on the original string.
Use strings for textual data. When representing complex data, parse strings and use the appropriate abstraction.
Above example describes you to execute the string datatype using the keyword called "var", assigned the function class names as a car with respective to the functioning of that.The getElementById() method returns the element that has the ID attribute with the specified value. We assigned the content in single and double quotes which we wanted to display on the output screen.

READ MORE

Simple Information about Javascript Comments

In JavaScript comments can be used to explain JavaScript code, and to make it more readable.These javascript comments can also be used to prevent execution, when testing alternative code.

Description

JavaScript supports three different types of comments:
  1. Multiple-line C-style comments. Everything between /* and */ is a comment
  2. For example:
    /* This is a comment */
    /* C-style comments can span
    as many lines as you like,
    as shown in this example */
  3. Single-line comments of C++ style. These comments begin with // and continue up to the next line break:
  4. // This is a one-line comment
  5. One-line comments with the HTML comment-opening sequence (< --). Note that the JavaScript interpreter ignores the closing characters of HTML comments (-->).
  6. <! -- This is treated as a one-line JS comment
    <! -- It works just like a comment beginning with //
    <! -- -->This is also a one-line JS comment
    <! -- --> because JS ignores the closing characters
    <! -- --> of HTML-style comments
HTML-style comments are not usually found in the middle of JavaScript code.(The // comments are simpler and easier to read.)

READ MORE