Javascrit
Javascrit
Javascrit
// let js = "amazing";
// console.log(40 + 8 + 23 - 10);
// console.log(firstName);
// console.log(firstName);
// console.log(firstName);
// console.log(myFirstJob);
/************************Data Types***************/
// let javascriptIsFun = true;
// console.log(javascriptIsFun);
// // console.log(typeof true);
// console.log(typeof javascriptIsFun);
// // console.log(typeof 23);
// // console.log(typeof 'Jonas');
// javascriptIsFun = 'YES!';
// console.log(typeof javascriptIsFun);
// let year;
// console.log(year);
// console.log(typeof year);
// year = 1991;
// console.log(typeof year);
// console.log(typeof null);
// lastName = 'Schmedtmann';
// console.log(lastName);
// ******************************Assignment operators
// let x = 10 + 5; // 15
// x += 10; // x = x + 10 = 25
// x *= 4; // x = x * 4 = 100
// x++; // x = x + 1
// x--;
// x--;
// console.log(x);
// *********************************Comparison operator
// console.log(ageJonas > ageSarah); // >, <, >=, <=
// console.log(ageSarah >= 18);
// *********************************Operator Precedence
// const now = 2037;
// const ageJonas = now - 1991;
// const ageSarah = now - 2018;
// let x, y;
// x = y = 25 - 10 - 5; // x = y = 10, x = 10
// console.log(x, y);
// const jonas = "I'm " + firstName + ', a ' + (year - birthYear) + ' year old ' +
job + '!';
// console.log(jonas);
// const jonasNew = `I'm ${firstName}, a ${year - birthYear} year old ${job}!`;
// console.log(jonasNew);
// console.log(`String
// multiple
// lines`);
// let js = "amazing";
// if (js == "amazing") {
// } else {
// alert("Learning js is Boring!");
// }
/*****************alert function*****************/
// alert("Learning js is really Fun!");
// console.log(5 + 6 + 45);
// let firstname = "Aryan gupta";
// console.log(firstname);
/******************data types**************/
// let age = 23; // number data types
// let Firstname = "Aryan"; // string data types
// let fullAge = true; // Boolen data types
// let children; // undefined as no value is assigned to it
// let n = null; // empty vale;
// symbol is also a data type which we discussed later
// BigInt is anather data types which we also disscuss later in course
// console.log(2.6 + 7.4);
// console.log(typeof 2.6);
// firstname = "dhairya";
// console.log(firstname);
// console.log(2 ** 3);
// const firstname = "Aryan";
// const position = "student";
// const birthyear = 2003;
// const year = 2022;
// const aryan =
// "I'm " +
// firstname +
// " ,a " +
// (year - birthyear) +
// " years old " +
// position +
// "!";
// console.log(aryan);
/*****************template literal*********************/
// const aryannew = `I'm ${firstname}, a ${
// year - birthyear
// } year old ${position}!`;
// console.log(aryannew);
/********************if else***************************/
// const age = 18;
// const isoldenough = age >= 18;
// if (isoldenough) {
// console.log(`aryan can start driving`);
// } else {
// console.log(`you need to wait for ${18 - age} more years to start driving!`);
// }
/*****************typeconversion*********************/
// const inputYear = "1991";
// console.log(Number(inputYear), inputYear);
// console.log(Number(inputYear) + 18);
// console.log(Number("aryan"));
// console.log(typeof NaN);
// console.log(String(28));
/***********type coercion*******************/
// need to be updated later
*****************************imp**************************//
/***************ternary operator******************/
//need to be updated later
*****************************imp**************************//
/************ Getting an input from a user***********/
// const query = prompt(`what is your favourite number: `);
// console.log(query);
/*************strict mode***************/
//activating strict mode below:-
"use strict"; // need to be first line of js file otherwise not work comment
ignored
// strict mode enabled 🙂🙂
// strict mode help us to find the errors more precisely and keep the list of
reserved words which can be used in future
// for example:-
// let drivings = false;
// const testPass = false;
// let testPass = prompt("test passed?"); ignore this message for now
// if (testPass) drivings = true;
// if (drivings) console.log("You can drive now🙂👍");
// else console.log(`you can't drive until 7 month😱😨`);
/***************FUNCTION**************/
// -> A function holds one or more complete lines of codes .
// function logger() {
// console.log("welcome to our five star to our restaurant✨🌟");
// console.log(`your order for ${fruitProcessor(9, 5)} is completed`);
// let is = prompt("enter yes if you want to visit again!❓");
// if (is === "yes") {
// logger();
// } else {
// console.log("Hope you have enjoyed. Please visit again🙂");
// }
// }
// !!NOTE: primitive value are immutable i.e, can't be changed if declared with
'const' but array is not primitive so we can change the elements of an array but
not the whole array
// exercise#1
// const calcage = (birthYear, currentYear) => currentYear - birthYear;
// const years = [1990, 1967, 2002, 2003, 2005];
/**************ARRAYS Methods*******************/
// 1) push : push method adds element to the end of an Array.
// const friends = ['sohail', 'manas', 'lalit', 'dhairya', 'ayush'];
// friends.push(`himanshu ${18} years old`);
// console.log(friends);
// 3) pop : pop will remove the last element from the Array and is just opposite of
push method.
// const friends = ['sohail', 'manas', 'lalit', 'dhairya', 'ayush'];
// friends.pop();
// console.log(friends);
// const removedElement = friends.pop() // this returns the remove element.
// console.log(removedElement);
// 6) includes : includes instead of returning the index of the element will simply
return true if the element is in the array and false if it's not .
// const friends = ['sohail', 'manas', 'lalit', 'dhairya', 'ayush'];
// console.log(friends.includes('Aryan'));
// console.log(friends.includes('manas'));
// !!NOTE: includes method uses strict equality for this check. example: if we push
some value to this array and is number instead of string so friends.push() which
remember will add a value to the end of the array . so if we check for that added
element it will not work , so it would say false,and this is because testing with
strict equality which means it will not do type coercion. and if both matches the
type it will work!;
// const profile = {
// firstName: `Aryan`,
// lastName: 'Gupta',
// age: calcage(2003, 2022),
// profession: 'student',
// job: 'coder',
// friends: ['sohail', 'manas', 'lalit', 'dhairya', 'ayush', 'vivek', 'Himanshu
sahu']
// };
// --> challenge
// " jonas has 3 friends and his best friend is called 'michael'"
// solution
// console.log(`${profile.firstName} has ${profile.friends.length} friends and his
best friend is '${profile.friends[profile.friends.indexOf('dhairya')]}'.`);
// const profile = {
// firstName: `Aryan`,
// lastName: 'Gupta',
// age: 19,
// profession: 'student',
// job: 'coder',
// friends: ['sohail', 'manas', 'lalit', 'dhairya', 'ayush', 'vivek', 'Himanshu
sahu'],
// birthyear: 2003,
// currentYear: 2022,
// hasDriverLicence: true,
// // calcAge: () => this.currentYear - this.birthyear // shows error
// calcAge: function () {
// console.log(this);
// return this.currentYear - this.birthyear;
// }
// };
// console.log(profile.calcAge());