0% found this document useful (0 votes)
5 views

javascript

The document provides a comprehensive overview of JavaScript programming concepts, including functions, arrays, objects, conditional statements, loops, and string manipulation. It also covers advanced topics such as higher-order functions, array methods like forEach and map, and the use of the Math and Date objects. Overall, it serves as a practical guide for making websites responsive and interactive through JavaScript functionalities.

Uploaded by

pv912066
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

javascript

The document provides a comprehensive overview of JavaScript programming concepts, including functions, arrays, objects, conditional statements, loops, and string manipulation. It also covers advanced topics such as higher-order functions, array methods like forEach and map, and the use of the Math and Date objects. Overall, it serves as a practical guide for making websites responsive and interactive through JavaScript functionalities.

Uploaded by

pv912066
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

to make website responsive, interactive and by adding several functionalities to

the website

// // console.log("HEllo");
// console.log("Hello WOrld");

// // arrays;
// const arr = ["adsf", "asf", 2, true];
// console.log(arr);

// let a = 4;
// a = [3, 4, 5, 6];
// console.log(a);

// // functions
// function greetings() {
// console.log("Hello World");
// }
// greetings();

// // by arguments and parameters


// function call(a, b) {
// console.log("Hello " + a + " " + b);
// }
// call("Vishal", "Patil");

// // // return
// function add(a, b) {
// const c = a + b;
// return c;
// }
// const x = add(2, 3);
// console.log(x);

// // other way to define function


// const adding = (a, b) => {
// console.log("Adding....");
// return a + b;
// };

// console.log(adding(4, 5));

//objects - collection of properties, funtions - methods


// const person = {
// //key : value pairs,
// firstName: "Vishal",
// lastName: "Patil",
// age: 21,
// education: false,
// siblings: ["a", "b", "c"],
// greet: () => {
// console.log("HELLO");
// },
// walking: (x) => {
// console.log("Walking in " + x + " direction");
// return 10;
// },
// };
// console.log(person.firstName);
// console.log(person.age);
// console.log(person.siblings[1]);
// person.greet();
// console.log(person.walking("east"));
// person.firstName = "NoOne";
// console.log(person.firstName);
// console.log(person);

// // conditional operators
// let a = "2";
// let b = 2;
// console.log(a == b); // compares value
// console.log(a === b); // compares value and the datatype

// b = "2";
// console.log(a === b);

// //logical operator
// let person = {
// name: "Vishal",
// age: 21
// };

// if (person.name == "NOName" || person.age <= 21) {


// console.log("Allowed to enter");
// }

// //switch

// const dice = 3;
// switch (dice) {
// case 1:
// console.log("ONE");
// break;
// case 2:
// console.log("TWO");
// break;
// default:
// console.log("NOT ALLOWED");
// }

// //loops

// while, for , do-while

// let amount = 4;
// while (amount > 0) {
// console.log("Printed from while loop");
// console.log("idk");
// amount--;
// }

// let am = 4;
// do {
// console.log("printed from do-while");
// console.log("idk");
// am--;
// } while (am > 0);
// for (let i = 0; i <= 4; i++) {
// console.log("Printed from for loop");
// console.log("idk");
// }

//////////////////lecture 8/////////////////////////////////////
// //string properties
// //String methods -- returns the string
// //creates object of string and jS wraps
// // creates new memory instead of changing original string

let text = "Vishal Patil";

// console.log(text.length);

// const x = text.toUpperCase();
// console.log(x);
// const y = text.toLowerCase();
// console.log(y);

// text = " Vishal ";


// const z = text.trim();
// //trims down first and last word spaces
// console.log(z);

//can apply two functions on same time


// const a = text.trim().toLowerCase();
// console.log(a);

// const b = text.indexOf("i");
// console.log(b);

//.includes()-- check if the mentioned substring includes in the string


// console.log(text.includes("Pat"));

// //* slice()--to get substring from a string


// // .slice(l,r)=> from index l to r-1;
// console.log(text.slice(2, 6));
// console.log(text.slice(2));

// // can take indexes bakcwards


// console.log(text.slice(-1));
// console.log(text.slice(-2));

// //template literals
// // strings can be initialised in double quote and single quote
// //yet there is another powerful way (back ticks ` `)

// const firstName = `Vishal`;


// const secondName = `Patil`;
// console.log("Hello I'm " + firstName + " " + secondName);
// //instead in back ticks we dont have to give +
// console.log(`Hello I'm ${firstName} ${secondName}`);

///// array properties

// //Array methods
// const arr = [1, 2, 3];

// // //length
// // console.log(arr.length);

// // //.concat(arr2);
// const arr2 = [5, 6, 7, 8, 9];
// const x = arr.concat(arr2);
// console.log(x);

// // //reverse();
// // console.log(arr.reverse());

// // //.push() pop();
// // arr.push(4);
// // arr.push(4);
// // arr.push(4);
// // console.log(arr);

// // arr.pop();
// // arr.pop();
// // arr.pop();
// // console.log(arr);

// const firstNames = ["Vishal", "Arun", "First"];


// const secondNames = ["Patil", "Sharma", "Name"];

// const names = [];


// for (let i = 0; i < firstNames.length; i++) {
// names.push(`${firstNames[i]} ${secondNames[i]} `);
// }
// console.log(names);

// //calling by funtion
// const printarr = (a) => {
// for (let i = 0; i < a.length; i++) {
// console.log(a[i]);
// }
// };
// printarr(arr);

// //references vs values
// // primitive datatypes--> pass by value
// const number = 1;
// let number2 = number;
// number2 = 4;

// console.log(number, number2);

// // hence when we change number2 there is no change in


// // number because its pass by value just values copied

// // objects-->pass by references
// const obj1 = {
// a: 3,
// b: 6
// };

// const obj2 = obj1;


// obj2.a = 4;
// console.log(obj1);
// console.log(obj2);

// // you will see that changes are made in both


// // since its pass by reference

// //Null vs Undefined
// //Undefined-->when JS cant value a variable
// //NULL--> developers assign this value
// let number = 20 + null;
// console.log(number);
// let number2 = 20 + undefined;
// console.log(number2);

// truthy and falsy


// truthy = true, falsy= false

// everything in JS is considered as truthy


// except
// falsy= "", '', ``, 0, -0, NaN, false, null, undefined

// operators
// unary operators = ! , single opearand
// binary operator = +,-,/ , two operators(a+b),a and b are operands
// ternary operator = ex:
// (condition) ? (return if true) : (return false)

// Global scope vs Local scope

// fun{
// //code block
// }

//Global scope
// variable declared can be accessed in any code
//block and outsite code block too

//Local scope
// variable dec in code block can br accessed
// within code block

// // variable lookup

// const Globalnum = 1000;

// function add(a, b) {
// const Globalnum = 5;
// const res = a + b + Globalnum;
// function multiply() {
// const num = 100;
// console.log(num * res * Globalnum);
// }
// multiply();
// console.log(res);
// }
// add(3, 4);
// // Globalnum will look for the nearest declared value

// // function ==> variable


// // // function can be written in variable

// // const add = (a, b) => {


// // console.log(a + b);
// // };
// // add(3, 4);

// // function can be passed as an argument to another function


// // called as callback fun
// // function to which it is passed is as argument
// // is called as higher order fun

// function morning(name) {
// return `Good Morning ${name}`;
// }
// function afternoon(name) {
// return `Good Afternoon ${name}`;
// }
// function greet(name, callback) {
// const myName = "Gandu";
// console.log(`${callback(name)}, My name is ${myName}`);
// }
// greet("Vishal", morning); //calling fun in fun
// greet("Vishal", afternoon); // passing as reference not as afternoon()

// Powerful Array Methods


// forEach, map, filter, find
// by using the above all we can iterate over the array

// let numbers = [1, 3, 2, 4, 5];

// //simple for loop


// for (let i = 0; i < numbers.length; i++) {
// console.log(numbers[i]);
// }

// remember syntax
// //forEach
// numbers.forEach((number) => {
// console.log(number);
// });

// let persons = [
// { name: "Vishal", department: "MME", age: "21", id: 1 },
// { name: "Naman", department: "MME", age: "25", id: 2 },
// { name: "OND", department: "MME", age: "24", id: 3 }
// ];

// // //size of the new Arr= size of the original arr


// const newArr = persons.map((person) => {
// console.log(person.name);
// return person.age; // map can store values hence we can return some value to
each index
// // if we dont return value then the newArr will not have any valid index in
array
// });
// console.log(newArr);

// //filter function =>also returns a new array


// // the size is not mecessarily same

// const newArr = persons.filter((person) => {


// if (person.age <= 24) return true;
// return false;
// });

// console.log(newArr);

// //find
// // it returns the first element which match the condition

// const condi = persons.find((person) => {


// if (person.id === 2) {
// return true;
// }
// return false;
// });
// console.log(condi);

// // Math

// const number = 4.565;


// console.log(Math.floor(number));
// console.log(Math.ceil(number));
// console.log(Math.sqrt(number));

// const pi = Math.PI;
// console.log(pi);

// console.log(Math.min(34, 34, 45, 4, 5, 3, 52, 42, 64));


// console.log(Math.max(34, 34, 45, 4, 5, 3, 52, 42, 64));

// const randomN = Math.random();


// console.log(randomN);

// //Date
// const today = new Date();
// console.log(today);
// console.log(today.getSeconds());
// console.log(today.getDay());
// console.log(today.getMonth());

You might also like