// <script type = "text/javascript"> </script ---head section
// <script type="text/javascript" src="externalFile.js" ></script
// JS DATATYPES :
// Numbers, Strings, Booleans, undefined, Null
// js Variables
var moneyVariable = 100.25;
var nameVariable = "myname";
// function or method
function sayHello(){
console.log("helloworld")
//condition withlogical operators
{ if (a == b && b = a || c < d){
// condition
}else if(10 > 5) {
// condition
}else{
// condition
}
} }
function switchStmt(){
switch (expression){
case "condition" 1: doSomething;
break
case "condition" 2: doSomething;
break;
default: doSomething;
}
}
// loops
// while loops
while (a > b){
// run code if condition is true
}
// do while run at least once.
do{
// code to run
var count = 0;
count++;
}while (count < 1000){
// increment count again
}
// for loops
/* for (init; test condition; iteration stmt){
statements to execute if test is true
}
*/
for (count = 0; count <10; count++){
document.write("count": +count);
}
// for in loop
var books = new book("c++", "java");
for (book in books){
console.log(book)
}
var books = new book();
book = {title: "c++", title: "java"};
for (title in book){
console.log(title)
}
// loop control
var x = 1;
document.write("Entering the loop<br /> ");
while (x < 20)
{
if (x == 5){
break; // breaks out of loop completely
}
x = x + 1;
document.write( x + "<br />");
if (x >= 5){
// continue skip rest of loop
}
}
document.write("Exiting the loop!<br /> ");