JavaScript -high level language (now) -case senstive -not typesafe -.js -initially it is function oriented , now it supports oops -is executed independently using Node -no main() -no explicit datatypes -it is a collection of objects -every statement is terminated with semicolon (;), but not mandatory Price = 99; console.log('welcome to javascript'); ---------- Price = 99; console.log(Price); --------------------- Price = 99; console.log('Price ' + Price); -------------------------------- Price console.log(Price); ReferenceError: Price is not defined --------------------------------------- Price = 99.29; console.log(Price + ' ' + typeof(Price)); Price = 399; console.log(Price + ' ' + typeof(Price)); Price = "JavaScript"; console.log(Price + ' ' + typeof(Price)); -------------------------------------------- Price = 399; console.log(Price + ' ' + typeof(Price)); Price = "JavaScript"; console.log(Price + ' ' + typeof(Price)); Price = 'ashok it'; console.log(Price + ' ' + typeof(Price)); Price = 'a'; console.log(Price + ' ' + typeof(Price)); Price = 'admin#1234'; console.log(Price + ' ' + typeof(Price)); ---------------------------------------- Price = 399; console.log(Price + ' ' + typeof(Price)); Price = true; console.log(Price + ' ' + typeof(Price)); Price = false; console.log(Price + ' ' + typeof(Price)); ------------------------------------------ Price = 399; console.log(Price + ' ' + typeof(Price)); Price = "12/03/2025"; console.log(Price + ' ' + typeof(Price)); -------------------------------------------- Price = 399; console.log(Price + ' ' + typeof(Price)); Price = "12/03/2025"; console.log(Price + ' ' + typeof(Price)); Price = null; console.log(Price + ' ' + typeof(Price)); Price = undefined; console.log(Price + ' ' + typeof(Price)); Price = []; console.log(Price + ' ' + typeof(Price)); Price = {}; console.log(Price + ' ' + typeof(Price)); -------------------------------------------- Price = 399; console.log(Price + ' ' + typeof(Price)); function Add(x,y) { console.log(x+y); } Add(19,29); Price = Add; console.log(Price + ' ' + typeof(Price)); Price(10,20); ----------------------------- datatypes - variables -no need of datatypes to declare a variable. -use of variables with out declaring them is possible -implicit datatypes are available -datatype of a variable is decided based on the value assigned to it. -to use a variable, it should be declared or initialized. -value of a variable is allowed change -datatype of a variable can be changed implicit or primitive datatypes number => when variable is assigned with a numeric value of any type including floating point string => when variable is assigned with a any type of content enclosed by double quotes or single quotes boolean => when variable is assigned with true or false undefined => when a variable is assigned with undefined object => when variable is assigned with null, [] , {} function => when a variable is assigned with function name ----------------------------------------------------------------- DAY - 2 -------- x = Number(); console.log(x); output : 0 -------------------- x = Number(99); console.log(x); ------------------- x = Number(99); console.log(x + ' ' + typeof(x)); 99 number -------------------------------- x = Number('javascript'); console.log(x + ' ' + typeof(x)); NaN number ------------------------------- x = Number(true); console.log(x + ' ' + typeof(x)); 1 number -------------------------------- x = Number(false); console.log(x + ' ' + typeof(x)); 0 number ------------------------------ x = String(); console.log(x + ' ' + typeof(x)); string ----------------------------- x = String('Ashok It'); console.log(x + ' ' + typeof(x)); Ashok It string ----------------------------- x = String("Ashok It"); console.log(x + ' ' + typeof(x)); Ashok It string --------------------------------- x = String(true); console.log(x + ' ' + typeof(x)); ------------------------------ x = String(123456); console.log(x + ' ' + typeof(x)); -------------------------------- data = 'testing'; x = String(data); console.log(x + ' ' + typeof(x)); ------------------------------------ data = 'testing'; x = String('data'); console.log(x + ' ' + typeof(x)); data string ---------------------------------- x = Boolean(); console.log(x + ' ' + typeof(x)); ---------------------------------- x = Boolean(true); console.log(x + ' ' + typeof(x)); ---------------------------------- x = Boolean(false); console.log(x + ' ' + typeof(x)); ----------------------------------- x = Boolean(1); console.log(x + ' ' + typeof(x)); ---------------------------------- x = BigInt(99); console.log(x + ' ' + typeof(x)); 99 bigint ---------------------------------- x = Object(); console.log(x + ' ' + typeof(x)); --------------------------------- x = Object(99); console.log(x + ' ' + typeof(x)); --------------------------------- x = Object('Arjun'); console.log(x + ' ' + typeof(x)); ---------------------------------- x = Object(true); console.log(x + ' ' + typeof(x)); --------------------------------- x = Object(null); console.log(x + ' ' + typeof(x)); ---------------------------------- x = Object(undefined); console.log(x + ' ' + typeof(x)); --------------------------------- x = Date(); console.log(x + ' ' + typeof(x)); --------------------------------- Number() String() BigInt() Boolean() Object() Date() --------------------------------- declarion of variables var let var Price = 99; console.log(Price + ' ' + typeof(Price)); ----------------------------------------- let Price = 99; console.log(Price + ' ' + typeof(Price)); ----------------------------------------- var Price console.log(Price + ' ' + typeof(Price)); undefined undefined Note: a variable without value becomes undefined ---------------------------------------- Operators : Arithmetic Operators + - * / % * var x = 10; var y = 2; var z = 3; console.log(x + y); console.log(x - y); console.log(x * y); console.log(x / y); console.log(x % y); console.log(x % z); console.log(x ** y); -------------------------------- var x = true; var y = false; console.log(x + y); console.log(x - y); console.log(x * y); console.log(x / y); ------------------------------ var x = 10; var y = 3; console.log(x + y); console.log(x - y); console.log(x * y); console.log(x / y); 13 7 30 3.3333333333333335 ------------------------- sign operators + - var x = +10; var y = -6; console.log(x + ' ' + y); ------------------------------ x = 10 y = 2 z = x + y; x + y ---> arithmetic expression x y ----> operands + ------> operator ---------------------------- increment and decrement ++ -- var x = 10; var y = x; console.log(x + ' ' + y); ------------------------------- var x = 10; var y = ++x; //(pre) increment first - assign later console.log(x + ' ' + y); ---------------------------------- var x = 10; var y = --x; //(pre) decrement first - assign later console.log(x + ' ' + y); ---------------------------------- var x = 10; var y = x--; //(post) assign first - decrement later console.log(x + ' ' + y); ---------------------------------- var x = 10; var y = x++; //(post) assign first - increment later console.log(x + ' ' + y); ---------------------------------- short-cut operators += -= *= /= %= var x = 10; x = x + 2; // x = 10 + 2; // x = 12; console.log(x); ----------------------------- var x = 10; //x = x + 2; x += 2; console.log(x); ----------------------------- var x = 10; //x = x - 2; x -= 2; console.log(x); -------------------------- var x = 10; //x = x * 2; x *= 2; console.log(x); ------------------------- var x = 10; //x = x / 2; x /= 2; console.log(x); ------------------------- var x = 10; //x = x % 2; x %= 2; console.log(x); ------------------------- relative operators or comparison operators > < >= <= == === != Note: any valid relative expression always returns boolean value. so these are called boolean expressions. var x = 10; var y = 2; var z = 10; console.log(x > y); // 10 > 2--> true console.log(x > z); // 10 > 10 --> false console.log(x>=z); // 10 >= 10 --> true console.log(x < y); // 10 < 2 ---> false console.log(x < z); // 10 < 10 --> false console.log(x <= z); // 10 <= 10 ---> true console.log(x == y); // 10 == 2 ---> false console.log(x == z); // 10 == 10 ---> true console.log(x != y); // 10 != 2 ---> true console.log(x != z); // 10 != 10 ---> false ----------------------------------------------- var x = 10; var y = 10; var z = '10'; var a = '99'; var b = 'arjun'; console.log(x + ' ' + y + ' '+ typeof(x) + ' ' + typeof(y) + ' ' + (x == y)); console.log(x + ' ' + z + ' '+ typeof(x) + ' ' + typeof(z) + ' ' + (x == z)); console.log(x + ' ' + a + ' '+ typeof(x) + ' ' + typeof(a) + ' ' + (x == a)); console.log(x + ' ' + b + ' '+ typeof(x) + ' ' + typeof(b) + ' ' + (x == b)); console.log(x + ' ' + z + ' '+ typeof(x) + ' ' + typeof(z) + ' ' + (x === z)); ----------------------------------------------------------------------------------- logical operators && || ! && and || or -used to join multiple conditions together as one unit && -returns true, when all the joined condition's result is true -cond1 && cond2 && cond3 && ......&& condN -if any one condition's result is false, no need to evaluate the remaining conditions || or - returns true, when atleast one condition's result is true -cond1 || cond2 || cond3 || ......|| condN -if any one condition's result is true, no need to evaluate the remaining conditions ! - returns opposite of the condition's result console.log(true && true); console.log(true && false); console.log(false && true); console.log(false && false); true false false false ------------------------------ console.log(true || true); console.log(true || false); console.log(false || true); console.log(false || false); true true true false ------------------------------- console.log(true ); console.log(false); console.log(!true); console.log(!false); true false false true ------------------------------ console.log(!1); console.log(!0); ------------------------------ ternary operator ? : ----------------------------- control structures : -used to control the flow of execution among the statements of the program. -selection of one or more statements either to execute or to skip from execution based on a condition. console.log('Good Monring'); console.log('Good AfterNoon'); console.log('Good Evening'); cs are two types -non-iterative cs -iterative cs -non-iterative cs 1.if a.simple if - only one option if(condition) { // executes when the condition's result is true // some logic } b.if...else - two options if(condition) { // executes when the condition's result is true // some logic } else { // executes when the condition's result is false // some logic } c.if..else if...else..if...else (ladder if) if(condition1) { // executes when the condition's result is true // some logic } else if(condition2) { // executes when the condition's result is true // some logic } else if(condition3) { // executes when the condition's result is true // some logic } ----------------------- ----------------------- ----------------------- [else { // executes when all the condition's results are false // logic }] 4.switch - used to check one value against multiple options switch(variable/exp/value) { case value1: // logic break; case value2: // logic break; case value3: // logic break; --------------- --------------- --------------- --------------- default: // executes when no case value is matched break; } ------------------------------------- x = 10; y = 10; if(x < y) { console.log(x + ' is less than ' + y); } else if(x > y) { console.log(x + ' is greater than ' + y); } else { console.log(x + ' is equal to ' + y); } -------------------------------------------- x = 10; y = 10; if(x < y) { console.log(x + ' is less than ' + y); } else if(x > y) { console.log(x + ' is greater than ' + y); } else if(x == y) { console.log(x + ' is equal to ' + y); } -------------------------------------------- userType ='visitor'; // use different values switch(userType) { case 'admin': // if(userType == 'admin') console.log('load admin page'); break; case 'employee': console.log('load employee page'); break; case 'customer': console.log('load customer page'); break; case 'supplier': console.log('load supplier page'); break; case 'guest': console.log('load guest page'); break; default: console.log('invalid user type...check once'); break; } ----------------------------------------------------------- x = 35; switch(true) // true { case x>=90: // true == false console.log('A+'); break; case x>=80: // true == false console.log('A'); break; case x>=70: // true == false console.log('B'); break; case x>=60: // true == false console.log('C'); break; case x>=50: // true == false console.log('D'); break; case x>=35: // true == true console.log('E'); break; default: console.log('F'); break; } ------------------------------------------- iterative control structures a.while b.do..while c.for -used to execute one or more statements again and again based on a condition -avoids duplication of code -supports re-usability -write once - use many times. declaration and initialization of looping variable condition on looping variable's value change in the looping variable's value --------------- var i = 1; while(i<=6) // condition checking is at the starting /entry point { console.log(i + " inside the while loop " + (i<=6)) i = i +1; } console.log(i + " outside the while loop " + (i<=6)) 1 inside the while loop true 2 inside the while loop true 3 inside the while loop true 4 inside the while loop true 5 inside the while loop true 6 inside the while loop true 7 outside the while loop false ----------------------------------- var i = 1; do { console.log(i + " inside the do-while loop " + (i<=6)); i = i +1; }while(i<=6) console.log(i + " outside the do-while loop " + (i<=6)); ------------------------------------------------------------ var i = 11; do { console.log(i + " inside the do-while loop " + (i<=6)); i = i +1; }while(i<=6) console.log(i + " outside the do-while loop " + (i<=6)); 11 inside the do-while loop false 12 outside the do-while loop false Note: do-while executes at-least once even the condition's result is false. ------------------------------------------- var i = 11; while(i<=6) // condition checking is at the starting /entry point { console.log(i + " inside the while loop " + (i<=6)) i = i +1; } console.log(i + " outside the while loop " + (i<=6)) 11 outside the while loop false -------------------------------------------------- for --- var i; for(i=1;i<=6;i = i +1) { console.log(i + " inside the for loop " + (i<=6)) } console.log(i + " outside the for loop " + (i<=6)); 1 inside the for loop true 2 inside the for loop true 3 inside the for loop true 4 inside the for loop true 5 inside the for loop true 6 inside the for loop true 7 outside the for loop false ------------------------------------ var i; for(i=11;i<=6;i = i +1) { console.log(i + " inside the for loop " + (i<=6)) } console.log(i + " outside the for loop " + (i<=6)); 11 outside the for loop false ------------------------------------- var i=1; for(;i<=6;) { console.log(i + " inside the for loop " + (i<=6)) i = i +1; } console.log(i + " outside the for loop " + (i<=6)); ------------------------------------------------------- var i=1; for(;;) { console.log(i + " inside the for loop " + (i<=6)) i = i +1; } // unreachable code console.log(i + " outside the for loop " + (i<=6)); //infinite loop ----------------------------------- var i=1; for(;;) { console.log(i + " inside the for loop " + (i<=6)) if(i==6) { break; } i = i +1; } console.log(i + " outside the for loop " + (i<=6)); 1 inside the for loop true 2 inside the for loop true 3 inside the for loop true 4 inside the for loop true 5 inside the for loop true 6 inside the for loop true 6 outside the for loop true -------------------------------------------- array -> - collection of values - *may be of same type or different type or other arrays - stored in a conitinious memory location - indentified by their position called index. - index value starts with zero '0' and ends with array size minus one. example : array with 9 values index starts with 0 and ends with 8. - index can be string, but it is not reflects the size. - all values shares same name. - array in javascript created in two ways -using [] -using Array() - var arrayname = [val1,val2,val3,......valN]; - to read a value arrayname[index] - to assign a value arrayname[index] = value; array management: -creation of array -array values management -add -delete -edit/modify/update -search/find -sort -other -array methods ---------------------- var marks = [99,35,45,88,58,69]; console.log(marks[0]); console.log(marks[1]); console.log(marks[2]); console.log(marks[3]); console.log(marks[4]); console.log(marks[5]); 99 35 45 88 58 69 --------------------------- var marks = [99,35,45,88,58,69]; console.log(marks[0]); marks[0] = 89; console.log(marks[0]); ------------------------------ var marks = [99,35,45,88,58,69]; for(i in marks) { console.log(i + ' value ' + marks[i]); } 0 value 99 1 value 35 2 value 45 3 value 88 4 value 58 5 value 69 --------------------------------------------- var marks = [99,35,45]; for(i in marks) { console.log(i + ' value ' + marks[i]); } 0 value 99 1 value 35 2 value 45 ---------------------------- var marks = [99,35,45,66]; for(i in marks) { console.log(i + ' value ' + marks[i]); } 0 value 99 1 value 35 2 value 45 3 value 66 -------------------------------- var marks = []; for(i in marks) { console.log(i + ' value ' + marks[i]); } ------------------------ Creation of an array: using [] using Array() ---------------------------------- var marks = []; // empty array console.log(typeof(marks)); // object console.log('size of marks : ' + marks.length); //size of marks : 0 console.log(marks); //[] ----------------------------------- var marks = [88,44,99,55,46,39]; // with values - same type console.log(typeof(marks)); // object console.log('size of marks : ' + marks.length); //size of marks : 6 console.log(marks); //[ 88, 44, 99, 55, 46, 39 ] --------------------------------------------------------- var Product = [9009,'Apple','12pc',199,true]; // with values - different type console.log(typeof(Product)); // object console.log('size of Product : ' + Product.length); //size of Product : 5 console.log(Product); //[ 9009, 'Apple', '12pc', 199, true ] ----------------------------------------- var Student = [1009,'John Miller','MERN','17/03/2025','Adilabad',18000.00,true]; console.log(Student); console.log('size : ' + Student.length); ------------------------------------------ var FoodItem = [ 2009, 'Butter Masala Dosa', 125, 4.1, 2194, 'Best Seller', 'Veg', true, 'Butter-Masala-Dosa.jpg' ] console.log(FoodItem); console.log('size of FoodItem : ' + FoodItem.length); --------------------------------------------------------- https://www.bigbasket.com/media/uploads/p/m/40072494_12-bb-royal-organic-turtoor-dal.jpg?tr=w-154,q-80 ----------------------------------------------------------------------------------------------------- var Product = [ 9001, 'Organic Toor/Arhar Dal', 'bb Royal', '4', '20245 Ratings', 'Veg', '41% OFF', '500g', '1 kg', '2 kg', '29%', '41%', '33%', 150, 299, 589, 105.93, 177.21, 393.03, true, true, true, '40072494_12-bb-royal-organic-turtoor-dal.jpg', true ]; console.log(Product); console.log('size of Product: ' + Product.length); ------------------------------------------------------ Product -ProductId - only one value -Name - only one value -BrandName - only one value -TypeOfProduct -only one value -Rating - only one value -RatingBy - only one value -Quantity - multi valued property -Mrp - multi valued property -Discount - multi valued property -SalePrice - multi valued property -IsAvailable - multi valued property -ImagePath - only one value -Status - only one value Number of properties : 13 Number of values : 23 Note: to handle 23 values by using 13 properties -------------------------------------------- var Quantity = ['500g','1 kg','2 kg']; var Mrp = [150,299,589]; var Discount = ['29%','41%','33%']; var SalePrice = [105.93,177.21,393.03] var QtStatus = [true,true,true] var Product = [ 9001, 'Organic Toor/Arhar Dal', 'bb Royal', '4', '20245 Ratings', 'Veg', '40072494_12-bb-royal-organic-turtoor-dal.jpg', true, Quantity, Mrp, Discount, SalePrice, QtStatus ]; console.log(Product); console.log('size of Product: ' + Product.length); ------------------------------------------------------------------ var Quantity = ['500g','1 kg','2 kg']; var Mrp = [150,299,589]; var Discount = ['29%','41%','33%']; var SalePrice = [105.93,177.21,393.03] var QtStatus = [true,true,true] var Product = [ 9001, 'Organic Toor/Arhar Dal', 'bb Royal', '4', '20245 Ratings', 'Veg', '40072494_12-bb-royal-organic-turtoor-dal.jpg', true, Quantity, Mrp, Discount, SalePrice, QtStatus ]; console.log(Product); console.log('size of Product: ' + Product.length); console.log('Name :' + Product[1]); console.log('Brand :' + Product[2]); console.log("Rating :" + Product[3]); console.log("Rating Given By : " + Product[4]); console.log('Type of Product : ' + Product[5]); console.log('Image path : ' + Product[6]); console.log('Product is available : ' + Product[7] ); console.log("Quantity : " + Product[8]) console.log('1st Quantity : ' + Product[8][0] ) console.log('1st Mrp : ' + Product[9][0] ) console.log('1st Discount : ' + Product[10][0] ) console.log('1st SalePrice : ' + Product[11][0] ) ------------------------------------------------------ creating an array by using Array() var marks = Array(); // empty array console.log(marks); console.log(marks.length); ------------------------------- var marks = Array(9); // array with single value console.log(marks); // creates array with the given size console.log(marks.length); ------------------------------------------- var marks = Array(99,44,77,88); // array with multiple values console.log(marks); console.log(marks.length); ---------------------------- var Quantity = Array('500g','1 kg','2 kg'); var Mrp = Array(150,299,589); var Discount = Array('29%','41%','33%'); var SalePrice = Array(105.93,177.21,393.03); var QtStatus = Array(true,true,true); var Product = [ 9001, 'Organic Toor/Arhar Dal', 'bb Royal', '4', '20245 Ratings', 'Veg', '40072494_12-bb-royal-organic-turtoor-dal.jpg', true, Quantity, Mrp, Discount, SalePrice, QtStatus ]; console.log(Product); console.log('size of Product: ' + Product.length); console.log('Name :' + Product[1]); console.log('Brand :' + Product[2]); console.log("Rating :" + Product[3]); console.log("Rating Given By : " + Product[4]); console.log('Type of Product : ' + Product[5]); console.log('Image path : ' + Product[6]); console.log('Product is available : ' + Product[7] ); console.log("Quantity : " + Product[8]) console.log('1st Quantity : ' + Product[8][0] ) console.log('1st Mrp : ' + Product[9][0] ) console.log('1st Discount : ' + Product[10][0] ) console.log('1st SalePrice : ' + Product[11][0] ) --------------------------------------------------------- Read a value arrayname[index] Assign a value arrayname[index]=value; -------------------------------- var marks = [99,44,77,88,11,89,23,95,59]; console.log(marks); console.log(marks.length); console.log(marks[0]); // valid index values 0 to 8 console.log(marks[35]); // undefined Note: value from a non-existing index becomes undefined --------------------------------------------------------- var marks = [99,44,77,88,11,89,23,95,59]; console.log(marks); console.log(marks.length); console.log(marks[0]); // valid index values 0 to 8 marks[0] = 69; console.log(marks[0]); console.log(marks); marks[12] = 8; console.log('size : ' + marks.length); console.log(marks); //Note: when value assinged to a non-existing index //memory is allocated with the given index. -------------------------------------------------- var Product = []; // empty console.log(Product); console.log('size : ' + Product.length); Product[0] = 9009; console.log('size : ' + Product.length); Product[1] = 'Apple'; console.log('size : ' + Product.length); Product[2] = '1Kg'; console.log('size : ' + Product.length); Product[3] = 199.99; console.log('size : ' + Product.length); console.log(Product); --------------------------------------- var Product = []; console.log(Product); Product['ProductId'] = 9009; Product['ProductName'] = 'Green Mango'; Product['Quantity'] = '1Kg'; Product['Price'] = 99; console.log(Product); console.log('size : ' + Product.length); // 0 console.log(Product['ProductId']); console.log(Product['ProductName']); console.log(Product['Quantity']); console.log(Product['Price']); output [] [ ProductId: 9009, ProductName: 'Green Mango', Quantity: '1Kg', Price: 99 ] size : 0 9009 Green Mango 1Kg 99 ------------------------------- Array methods -add and remove -push() : used to append the given value/values/array at the end of the array and it returns the new size of the array. -unshift() - used to insert the value at the start of an array and returns the new size -pop() - used to remove the value from end of an array. It returns the removed value. -shift() - used to remove and return the value from the top/starting of an array. var marks = [99,44,77,88,11,89,23,95,59]; console.log('size ' + marks.length); console.log(marks.push(49)); // with single value console.log(marks); -------------------------------------------- var marks = [99,44,77,88,11,89,23,95,59]; console.log('size ' + marks.length); console.log(marks.push(49,19,29)); // with multiple value console.log(marks); -------------------------------------------- var marks = [99,44,77,88,11,89,23,95,59]; console.log('size ' + marks.length); console.log(marks.push([49,19,29])); // with array console.log(marks); -------------------------------------------- var marks = [99,44,77,88,11,89,23,95,59]; console.log('size ' + marks.length); console.log(marks.unshift(49)); // with single value console.log(marks); ------------------------------------ var marks = [99,44,77,88,11,89,23,95,59]; console.log('size ' + marks.length); console.log(marks.unshift(49,19,29)); // with multiple value console.log(marks); ------------------------------------- var marks = [99,44,77,88,11,89,23,95,59]; console.log('size ' + marks.length); console.log(marks.unshift([49,19,29])); // with array console.log(marks); -------------------------------------- var marks = [99,44,77,88,11,89,23,95,59]; console.log('size ' + marks.length); console.log(marks.pop()); // removes and returns the end value console.log(marks); console.log('size ' + marks.length); ------------------------------------- var marks = [99,44,77,88,11,89,23,95,59,[19,29,39]]; console.log('size ' + marks.length); console.log(marks.pop()); // removes and returns the end value // here the last value is array console.log(marks); console.log('size ' + marks.length); ---------------------------------------------------- var marks = [99,44,77,88,11,89,23,95,59]; console.log('size ' + marks.length); console.log(marks.shift()); // removes and returns the start value console.log(marks); console.log('size ' + marks.length); ----------------------------------------- var marks = [[12,23,29],99,44,77,88,11,89,23,95,59]; console.log('size ' + marks.length); console.log(marks.shift()); // removes and returns the start value // which is an array console.log(marks); console.log('size ' + marks.length); ------------------------------------------ var marks = [23,95,59]; console.log('size ' + marks.length); console.log(marks.pop()); console.log('size ' + marks.length); console.log(marks.pop()); console.log('size ' + marks.length); console.log(marks.pop()); console.log('size ' + marks.length); console.log(marks); console.log(marks.pop()); // undefined -------------------------------------- var marks = [23,95,59]; console.log('size ' + marks.length); console.log(marks.shift()); console.log('size ' + marks.length); console.log(marks.shift()); console.log('size ' + marks.length); console.log(marks.shift()); console.log('size ' + marks.length); console.log(marks); console.log(marks.shift()); // undefined Note: pop()/shift() on empty array returns undefined. ---------------------------------------------