JavaScript is a lightweight, interpreted programming language. It is designed for creating network-centric applications. It is complementary to and integrated with Java. JavaScript is very easy to implement because it is integrated with HTML. It is open and cross-platform.
The ECMA-262 Specification defined a standard version of the core JavaScript language.
- JavaScript is a lightweight, interpreted programming language.
- Designed for creating network-centric applications.
- Complementary to and integrated with Java.
- Complementary to and integrated with HTML.
- Open and cross-platform
JavaScript can “display” data in different ways:
- Writing into an HTML element, using innerHTML.
- Writing into the HTML output using document.write().
- Writing into an alert box, using window.alert().
- Writing into the browser console, using console.log().
OPERATORS OF JAVASCRIPT
| Operator | Example | Same As |
| = | x = y | x = y |
| += | x += y | x = x + y |
| -= | x -= y | x = x – y |
| *= | x *= y | x = x * y |
| /= | x /= y | x = x / y |
| %= | x %= y | x = x % y |
| <<= | x <<= y | x = x << y |
| >>= | x >>= y | x = x >> y |
| >>>= | x >>>= y | x = x >>> y |
| &= | x &= y | x = x & y |
| ^= | x ^= y | x = x ^ y |
| |= | x |= y | x = x | y |
| **= | x **= y | x = x ** y |
Data Types Of Javascript
var length = 16; // Number
var StreetName = “TerraCotta Crescent”; // String
var x = {firstName:”Preet”, lastName:”Kaur”}; // Object
Conditional Statements
There are four types of conditional statements such as :
- If Statement
- else Statement
- else if Statement
- switch Statement
Different Kinds of Loops
JavaScript supports different kinds of loops:
- for – loops through a block of code a number of times
- for/in – loops through the properties of an object
- While – loops through a block of code while a specified condition is true
- do/while – also loops through a block of code while a specified condition is true
What is JSON?
- JSON stands for JavaScript Object Notation
- JSON is lightweight data interchange format
- JSON is language independent *
- JSON is “self-describing” and easy to understand
JSON Example
{
“employees”:[
{“firstName”:”preet”, “lastName”:”kaur”},
{“firstName”:”Gurveer”, “lastName”:”Singh”},
{“firstName”:”Karanbir”, “lastName”:”Dhillon”}
]
}
JSON Syntax Rules
- Data is in name/value pairs
- Data is separated by commas
- Curly braces hold objects
- Square brackets hold arrays
Javascript Forms
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Can Validate Input</h2>
<p>Please input a number between 1 and 10:</p>
<input id=”numb”>
<button type=”button” onclick=”myFunction()”>Submit</button>
<p id=”demo”></p>
<script>
function myFunction() {
var x, text;
// Get the value of the input field with id=”numb”
x = document.getElementById(“numb”).value;
// If x is Not a Number or less than one or greater than 10
if (isNaN(x) || x < 1 || x > 10) {
text = “Input not valid”;
} else {
text = “Input OK”;
}
document.getElementById(“demo”).innerHTML = text;
}
</script>
</body>
</html>
Justin studied at Brock University and Humber College. He leads the team at websiteTOON Digital. He has been a featured speaker with the Toronto Board of Trade, Kitchener/Waterloo Board of Trade, Trade Accelerator Program, World Trade Centre Institute, and other educational bodies. He loves to read and plays Starcraft on the side.
