Category Archives: JavaScript

JavaScript Tutorial

JS RegExp Object

JavaScript RegExp Object The Javascript RegExp object consists of properties and methods that are used to find and replace characters that fit in a string. JavaScript Math Object Example Match() <script type=”text/javascript”> <!– var txt = “Los Angels is a magic city”; var a = /angels/i; document.write(txt.match(a)); //–> </script> Result: Angels Example Test() <script type=”text/javascript”> <!– var a=new… Read More »

JS Math Object

JavaScript Math Object The Javascript Math object is used for performing mathematical calculations using properties and functions like: max, min, round, random, sin, cos, sqrt, log, ceil, abs, e, pi. JavaScript Math Object Example Max() <script type=”text/javascript”> <!– var a = document.getElementById.innerHTML=Math.max(3,7); document.write(a); //–> </script> Result: 7 Example Min() <script type=”text/javascript”> <!– var a = document.getElementById.innerHTML=Math.min(3,7); document.write(a); //–>… Read More »

JS String Object

JavaScript String Object The Javascript String object is a series of characters in a character string. With String object you can manipulate strings. JavaScript Array Object Example 1: <script type=”text/javascript”> <!– var city=”New York city!”; document.write(city.length); //–> </script> Result: 14 Example 2: <script type=”text/javascript”> <!– var str=”Hello visitor, welcome to www.javascriptutorial.com “; var n=str.indexOf(“visitor”); document.write(n); //–> </script> Result:… Read More »

JS Array Object

JavaScript Array Object The Javascript Array object is a one-dimensional array that has several properties and methods. JavaScript stores lists of values in array. Create JavaScript Array Object Example 1: <script type=”text/javascript”> <!– var cities=new Array(); cities[0]=”London”; cities[1]=”New York”; cities[2]=”Toronto”; cities[3]=”Berlin”; cities[4]=”New Delhi”; document.write(cities[2]); //–> </script> Result: Toronto Example 2: <script type=”text/javascript”> <!– var cities=new Array(“London”, “New York”,… Read More »

JS Objects

JavaScript Objects JavaScript Objects An object is a collection of properties and methods withheld under one name. Properties Properties or attributes of an object describes the special features and identity. <script> var a=”Hello people!”; document.write(a.length); </script> Result: 13 Methods Methods or functions of an object are actions that can be performed on an object. <script> var a=”Hello people!”;… Read More »

JS Events

JavaScript Events JavaScript Events A JavaScript function is a section of code that perform a specific task when called. Calling a function is achieved by its name. Syntax: function function_name() { function code } Example: <html> <head> <script> function helloFunction() { alert("Hello people!"); } </script> </head> <body> <input type=”button” onclick=”helloFunction()” value=”Press button” /> </body> </html> Result: JavaScript Event… Read More »

JS Functions

JavaScript Functions JavaScript Functions A JavaScript function is a section of code that perform a specific task when called. Calling a function is achieved by its name. Syntax: function function_name() { function code } Example: <html> <head> <script> function helloFunction() { alert("Hello people!"); } </script> </head> <body> <button onclick="helloFunction()">Press button</button> </body> </html> Calling the Function: <script type=”text/javascript”> <!–… Read More »

JS While Loop Statement

JavaScript While Loop Statement JavaScript While Loop Statement While Loop statement is a repetitive statement which is executed after evaluating the condition. If the resulting value is true the the execution is repetead until becomes false. Syntax: while (condition){ If condition is true the the statement is executed } Example: <script type=”text/javascript”> <!– var a = 0; document.write(“Start… Read More »

JS For Loop Statement

JavaScript For Loop Statement JavaScript For Loop Statement For Loop statement – is a loop statement that evaluates the expression. If it meets the condition of initialization then increment the value of initialization and repeat execution steps until no longer meets execution. Syntax: for (initialization; condition; incrementation){ If condition is true then execute the statement }

JS Switch Case Statement

JavaScript Switch Case Statement JavaScript Switch Case Statement Switch Case statement is used when we have to chose between several individual cases after the evaluation of an expression. Syntax: switch (expression) { case v_1: statement_1; break; case v_2: statement_2; break; case v_3: statement_3; break; … case v_n: statement_n; break; [default: statement_n+1]; } Switch Case statement evaluates the expression.… Read More »