It is not necessary to define the data type when initializing the variables in Javascript. It automatically gets the data type of the variable according to the value stored in the variable. That is calling Dynamic Type Variables. Therefore Same variable can be used to store following kind of data in JavaScript
1. String
A set of characters can be stored by putting between the Double Quotes or Single Quote
Syntax:
var <variable name> = '<Value>' OR
var <variable name> = "<Value>"
Ex:
var student = "John"; // OR
var student = 'John';
var Relationship= "John's car"; // Can put single Quotes within Double Quotes
var car = 'John has "Toyota" car'; // Can put Double Quotes within Single Quotes
2. Number
Numbers in the can be written with or without decimal places.
var no1 = 50;
var no1 = 53.25;
This blog supports beginners to get deep knowledge about programming in HTML, CSS, JavaScript, php, asp and other Web technologies and VB, VB.net, Java,step by step from the beginning. All the programming Concepts discuss with simple examples for the readability. Try out daily uploaded lessons to be a Programmer.
Javascript - Comments
We are using comments to make Javascript more readable and comments are not executed by JavaScript. That can be used to explain the coding. In JavaScript, there are two types of comments can be used,
01. Single Line Comments
Single Line Comments begins with 02 forward slashes and there is no ending, its
applicable to the whole line which it puts.
Syntax:
// <Comment>
Ex:
// This is a single line Comment
var no = 0; // This is Number type variable
02. Multi Line Comments
Multi Line Comments begins with a /* and ends with */.
Syntax:
/* <Comment> */
Ex:
/* This is a Multi line Comment
Purpose of this comment is explain
the code with more than one line */
Subscribe to:
Posts (Atom)