Not the right essay? View 100,000 essays at TermPapersMonthly.com.
Submitted by imran on 05/01/2011 05:26 AM Flag This Paper
Join Now
Variable
var is used to create (define) variable in javascript.
var stringData = "JavaScript has strings\n It sure does";
var numericData = 3.14;
var booleanData = true;
String, Number and Boolean can be declare using var.
typeof
using typeof we can identify the type of the variable or data element.
Arrays
var myArray = [1,5,68,3];
var myArray = ["Thomas", true, 3, -47.6, "x"];
var myArray = new Array();
This defines myArray as an array with no particular length.
var myArray = new Array(4);
var myArray = new Array(1,5,"Thomas", true);
var myArray = new Array(4);
myArray[0] = 1;
myArray[1] = 5;
myArray[2] = "Thomas";
myArray[3] = true;
Input and Output in JavaScript
alert("This is an important message!");
var ans=confirm("Would you like to show the secrate?");
if(ans)
{
document.getElementById('sec_text').value="fun";
}
else
{
document.getElementById('sec_text').value="bla bla bla...";
}
var answer = prompt("What is your favorite color?","");
document.write("This text is not followed by a linebreak. ");
document.writeln("However this uses writeln().");
Javascript Primitives
parseInt
parseFloat
var headline = new String("Dewey Defeats Truman");
toString
Scope of Variable
var scope = "global";
function myFunction()
{
var scope = "local";
document.writeln("The value of scope in myFunction is: " + scope);
}
myFunction();
document.writeln("The value of scope in the global context is: " + scope);
Operator, Statement, Control Structure and Looping Structure, Function, Jump Statements everything remain same as like C
Date and Time
var d = new Date(Date.parse(“May 25, 2004â€));
var d = new Date(2003, 1, 5);
Method for different representation
• toDateString() — displays only the date part of a Date (only the month, day, and year) in an implementation-dependent format
• toTimeString() — displays only the time part of a Date (hours, minutes, seconds,...