Posts

Showing posts from August, 2022

JS - basic types and ways of writing function

//* basic types of function *// //1) without parameters and without return type function Tuljapur(){     console.log("hello") } Tuljapur() //2) with parameters and without return type function Solapur(x,y){     console.log(x+y) } Solapur(100,200) //3) with parameters and with return type function Dharashiv(x,y){     return x * y } let aa1 = Dharashiv(5,4) console.log(aa1) console.log(aa1*6) //* different ways of writing function *// //1) function declaration function addA(x,y){     return x + y } let a1 = addA(20,30) console.log(a1) //2) function expression let addB = function(x,y){     return x + y } let a2 = addB(50, 40) console.log(a2) //3) arrow function let addC = (x,y)=>{     return x + y } let a3 = addC(60,40) console.log(a3)

JS - Day 7

// for loop for(let i = 0; i < 4; i++){     console.log(i) // prints the indexes upto 3 from 0 i.e. 0,1,2,3 using loop } for(let i = 1; i < 4; i++){     console.log(i) // prints the indexes upto 3 from 1 i.e. 1,2,3 using loop } for(let i = 0; i < 4; i++){     console.log(fruits[i]) // prints the elements upto 3 index for array of fruits from 0 i.e. 0,1,2,3 } for(let i = 0; i < 3; i++){     console.log(fruits[i]) // prints the elements upto 2 index for array of fruits from 0 i.e. 0,1,2 } // *program 1 using for loop* // lets consider we have to calculate ages of some people, we have their year of birth let years = [1989,1990,1991,1992] let ages = [] // blank array to print the required value in this blank array for(let i = 0; i < 4; i++){     console.log(2022-years[i]) // we will get the ages of elements in years array but not in that blank array     // now to get the ages in that blank array, we will use 'push' m...

JS - Day 6

/// array let names =['ram', 'sham', 'ganesh', 'mahesh'] // this is the array console.log(names) // prints array as it is console.log(names[0]) // prints element at 0 index i.e. ram let a = names.length console.log(a) // prints length of array /// methods of array - push(), unshift(), pop(), shift(), includes(), indexOf() let cities = ['pune', 'mumbai', 'nagpur'] let b = cities.push('solapur') // put new element at end in array and returns new length of array when printed console.log(b) // prints new length of array console.log(cities) // prints arraay with 'solapur' at end let c = cities.unshift('dharashiv') // put new element at start in array and returns new length of array when printed console.log(c) // prints new length of array console.log(cities) // prints array with 'dharashiv' at start let d = cities.pop() // removes last element from array and returns removed element when printed console.l...

JS - Day 5

/// more methods for string - trimStart(), trimEnd(), trim() let a = ' jaipur' // here we put space at start let ab = a.length console.log(ab) // prints length of string 'a' considering that space i.e. length will be 7 let abc = a.trimStart() console.log(abc) // prints the string 'a' after trimming the space at start let b = "jaipur " // we put space at end let bb = b.trimEnd() console.log(bb) // prints the string 'b' after trimming the space at end let c = " jaipur " // we put space at both end let cc = c.trim() console.log(cc) // prints the string 'c' after trimming the space at both end /// more methods - startsWith(), endsWith(), charAt() let e = 'dharashiv' let ea = e.startsWith('d') console.log(ea) // prints the boolean value as true because sting 'e' starts with d let eb = e.startsWith('dha') console.log(eb) // prints the boolean value as true because sting 'e' starts with dha let...

JS - Day 4

/// String: string is the collection of characters.  // string is written in single or double quote or back quote  // Example of string let a = 'Ram'       // written in single quote  let b = "Sham"      // written in double quote let c = `Laxman`    // written in back quote let d = '1234'      // numbers written in quote is also a string //* In Javascript everything is an object so every object have some properties and methods // example: our body is an object it has properties like weight, height, colour etc.  // and the methods are walk, talk, sleep, sit etc. and performing that methods is action and when we get // something because of that then its is a return. like we do exercise and we get good muscles as a return. // like the above said example every object in JavaScript has properties & methods and method includes action and return //* In string every character has a stored index number // Exampl...

JS - Day 3

// Logical operations //1) And && // true && true      // meaning - both statements true // result: true // false && true     // meaning - 1st statement false & 2nd true // result: false // true && false     // meaning - 1st statement true & 2nd false // result: false // false && false    // meaning - both statements false // result: false //2) Or || // true || true      // meaning - both statements true // result: true    // false || true     // meaning - 1st statement false OR 2nd true // result: true // true || false     // meaning - 1st statement true OR 2nd false // result: true // false || false    // meaning - both statements false // result: false //3) Not ! // ! true       // meaning - statement not true // result: false // ! false      // meaning - statement not false // result...

JS - Day 2

// Function without parameter and without return type function add() { console.log(9+9) } add() // Function with parameter and without return type function addB(x,y) {     console.log(x+y) } addB(10,12) // Function with parameter and with return type function addC(x,y){     return(x+y) } let q = addC(12,14) console.log(q) console.log(q+5) console.log(q+q) console.log(q-q) // Data Types : number, boolean, string let x2 = 23 console.log(typeof x2) // number // any +ve, -ve, fraction number is a number let x3 = true console.log(typeof x3) // boolean // any statement whose value or output is only true or false is a boolean let x4 = "Ashish" console.log(typeof x4) // string // any character written in single or double quote is considered as a string // Comparison Operator // that compares LHS and RHS i.e. left hand side and right hand side // < less than, > greater than, <= is less or equal, >= is greater or equal, != is not equal // == is equal, === value eq...

JS - Day 1

let a = 15 console.log(a) let b = 25 console.log(b) console.log(a+b) console.log(a-b) console.log(a*b) console.log(a/b) console.log(a%b) let m = 100 let n = 200 console.log(m+n) console.log(m-n) console.log(m*n) console.log(m/n) console.log(m%n) let j = 111 let k = 222 console.log(j+k) console.log(j-k) console.log(j*k) console.log(j/k) console.log(j%k) const z = 5 const y = 4 console.log(z) console.log(z+y) console.log(z-y) console.log(z*y) console.log(z/y) console.log(z%y) function Calculator(j,k) {     console.log(j+k)     console.log(j-k)     console.log(j*k)     console.log(j/k)     console.log(j%k) } Calculator(10,20) -blog by Ashish Naik