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 */
Javascript - Variables
Javascript variables uses to contain information.
Syntax:
var <name> = <value>
Ex:
var No1 = 5;
var No2 = 10;
var total = No1 + No2;
Javascript Variable names;
1. must begins with a letter
2. can begins with $ or _
3. are case sensitive
How to define a Javascript Variable
1. Method 01
var carName = "Toyota"
2. Method 02
var carName;
carName = "Toyota";
Syntax:
var <name> = <value>
Ex:
var No1 = 5;
var No2 = 10;
var total = No1 + No2;
Javascript Variable names;
1. must begins with a letter
2. can begins with $ or _
3. are case sensitive
How to define a Javascript Variable
1. Method 01
var carName = "Toyota"
2. Method 02
var carName;
carName = "Toyota";
Web Programing for Beginners
Is this blog helpful for you? Can you recommend for someone?
I much appreciate your kind suggestions and comment to improve the contents & writing method of this blog. Because you are the actual reader of this site and strive to sharpen your web programming knowledge.
You may knowing further more about the discussed topics or have articles, links related to the topics please put it in your comment. Those comments more helpful others as well as me.
--
Best regards,
Priyal
PHP - Print the Processed data
It is the way to see the processed php data by sending it to the browser as an out put. You can display the contents within the browser to see the users. There are several ways allows in php to send out put to the browser. I'm discussed here most important & common methods here.
- echo() statement
This is the most common out put generation method in php. echo() statement accept multiple arguments.
syntax:
echo (string arg1[, string arg2, ...]);
PHP - Arrays
There are two types of array namely,
$bookName = "Sample Book";
$bookAuthor = "Author\'s Name";
$bookPublished = "April 02, 2013";
$bookPublisher = "Sample Book Publisher";
But you can store above all values to a single array.
- Single Dimensional Array
- Multi Dimensional Array
$bookName = "Sample Book";
$bookAuthor = "Author\'s Name";
$bookPublished = "April 02, 2013";
$bookPublisher = "Sample Book Publisher";
But you can store above all values to a single array.
- Single Dimensional Arrays
Ex:
$book = array(
"Sample Book",
"Author's Name",
"April 02, 2013",
"Sample Book Publisher"
) //use a book array to store above values
echo "Book Name : " . $book[0]; // Print 1st element of the array
PHP - Numbers
There are two types of Numbers can be declared with php.
- Whole Numbers
Integer data type uses to store positive or negative whole Numbers (without decimal points). It is not required to define integers because php is a loosely typed language. You are define a whole number without double quotes then it automatically evaluate as an integer value. But you can force the value store as integer by using casting.Ex:
1, -50
$num = 50 // Numbers are define without double or single quotes
$num = (int) 50 // This is a casting example. Here force to store the value as integer.
$num = (int) "5years" // Taken the value as 5
$num = (int) "age10" // Taken the value as 0 - Real Numbers
Double and Float data type uses to store positive or negative whole Numbers (with decimal points).
Ex:
15.3325, -5.586240
$num = 50.5589// Real Numbers are define without double or single quotes
$num = (double) 50.569 // This is a casting example. Here force to store the value as real number.
$num = (double) "5.85Km" // Taken the value as 5.85
$num = (double) "age10.6" // Taken the value as 0
$num = (float) "10.53yards" // Taken the value as10.53
Subscribe to:
Posts (Atom)