JavaScript Full Course 2023
JavaScript Full Course 2023
- [JavaScript Video](https://youtu.be/lGmRnu--iU8)
### Assignments
**1.1:** Create a code to check difference between `null` and `undefined` data type. Also check their
type using `typeof`.
**1.2:** Which type of variables (var, let or const) must be **initialized** at the time of declaration?
```js
```
```js
console.log(result);
```
```js
console.log(result1, result2);
```
**1.6:** Guess the **Output** and explain Why?
```js
console.log(result);
```
```js
let num1 = 2;
let num2 = 5;
console.log(result);
```
```js
console.log(result);
```
```js
let a = 5;
let b = 7;
let c = 8;
console.log(result);
```
**1.10:** If your State is split into **four** equal parts such that in each part there are **1/4**
number of people live. You have to find how many people would live in each part? which operators will
you use ?
```js
let i = 4;
if (j === 1 || i === 6) {
continue;
} else {
console.log(i, j);
if (i === 7) {
break;
```
```js
let i = 0;
console.log(i);
```
**2.3:** Write a simple **Program** in which You have to print first **10** numbers in
**descending** order (10...1)?
**2.4:** Lets say `John` is looking a new `country` to live in. He want to live in a country that speaks
`English`, has less than 10 million people. One of the `food` option between these two must present
`Spanish food` OR `English food`.
**Write** an if/else if statement to help john figure out Your country is right for him?
```js
console.log(i);
console.log(i);
```
If **both** true show any message(**I can sit in exam**) in the console?
**2.7:** Create two variables `grade` and `passingYear`.Check if your `grade == "A"` and `passingYear <
2020` with the help of **ternary** operator(Not allowed to use any logical operator).If both condition
`true` print on console **Qualify**. Otherwise **Fail**
## Chapter 3 (Functions)
### Assignments
**3.1:** Create a **function Declaration** called `describeYourState` Which take three parameters
`Population`, `traditional food` and `historical place`. Based on this input function should return a `String`
with this format.
**My state population is ** Its traditional food is ** and historical place name is \_\_\_**
**3.2:** Create a **function expression** which does the exact same thing as defined in **Question
1**
**3.3:** Create function **addition** which takes two numbers as an argument And return the result
of **sum of two numbers**
**Important Note**: In the function call you are **not** passing any **parameter**. You can modify
function to achieve this.
```js
Example;
console.log(addition()); //You are not allowed to modify this line any more
```
**3.4:** Identify which **type** of value passed below into the function **greet()**. What will be the
return value of greet ?
```js
let person = {
name: 'john',
age: 25,
};
function greet(person) {
greet(person);
```
**3.5:** Create **higher** order function named as `transformer` which take `string` and
`firstUpperCaseWord` function as an arguments. `firstUpperCaseWord` is function which make first word
UpperCase from a given `String`.
```js
input
output
and so on.
```
```js
`Welcome ${name}`;
};
console.log(arrowFunction('Programmers'));
```
**3.8:** Create a JavaScript **Function** to find the area of a triangle where lengths of the three of its
sides are 5, 6, 7. : **Area = Square root of√s(s - a)(s - b)(s - c)** where **s** is half the perimeter, or
**(a + b + c)/2**.
```js
output: 14.69;
```
**3.9:** Create a JavaScript **Function** to capitalize the first letter of each word of a given string.
```js
```
## Chapter 4 (Objects)
### Assignments
```js
console.log(Math.round(Math.random() * 10));
```
**4.2:** Create an object called `country` for a country of your choice, containing properties `name` ,
`capital`, `language`, `population` and `neighbors`
```js
let car = {
color: 'Blue',
model: 2021,
company: 'Toyota',
};
console.log(car[carColor]);
console.log(car.carColor);
```
**4.4:** Create a method **describeCar** inside `car` object in which you have to print like this in
console using template literals
**4.5:** Generate random numbers between 0 and 10 using **trunc** method of **MATH** object
```js
Example
getRandomNumbers(){
}
Ouput value 0-10
```
```js
arr.forEach(elem =>{
if(elem == 1){
continue;
console.log(elem);
})
```
```js
let airplane = {
atacode: 'FI',
ratings: 4.9,
book(passenger, flightNum) {
console.log(
);
},
};
bookMethod('john', 8754);
```
```js
let arr = [1, 2, 3, 4];
console.log(elem);
```
- **removeItem(itemName)**: this function should remove any item which matches itemName. _Hint :
search for index of itemName and then remove it_
## Chapter 5 (DOM)
### Assignments
**5.1:** Explain difference between **innerText** and **innerHTML** in the following example?
**HTML**
```html
<div id="content">
<h2>Hello Coders</h2>
</div>
```
**JavaScript**
```js
console.log(content.innerHTML);
console.log(content.innerText);
```
### Assignments
**HTML**
```html
<input
type="password"
name=""
class="inputPass"
placeholder="Enter Password"
/>
</form>
```
**JavaScript**
```js
e.preventDefault();
} else {
});
```
### Assignments
**7.1:** You have given array of **strings**. Your task is to obtain last **two** elements of given array
using **slice** method?
```js
Input;
Ouput[('Neha', 'harry')];
```
**7.2:** You have given an array of **5** elements(1-5). Your task is defined as below.
```js
```js
```
Example : arr.slice(-2);
**7.4:** Write **three** different methods/approaches to get **last** element of the array?
```js
```
**7.5:** You have given an array of **nums**. Create new Array with the help of **nums** array. In
new Array each element will be a result of **multiplication by 2** of the original array element
```js
```js
Example: Input;
output;
```
**7.6** You have given an array of **scores** in which score of each student stored. Create a new array
with the help of original **scores** array in which only those scores exist **greater** than 75%
```js
```
```js
let scores = [55, 76, 35, 77, 88, 97, 120, 136, 140];
```
**7.7:** You have given an array of numbers **nums**. You have to find **sum** of all array elements
using **reduce** method?
```js
```
**7.8:** You have given an array of numbers **nums**. You have to find the index of value **8** using
**built-in** method of array?
```js
```
**7.9:** You have given an array of **objects** of users as below. Find the specified **user** with
`name = "John" `
Also find the **position** `(index+1)` of that **user** inside the array?
```js
let users = [
name: 'Paul',
age: 24,
verified: true,
},
{
name: 'John',
age: 21,
verified: false,
},
name: 'Neha',
age: 19,
verify: true,
},
];
```
```js
console.log(res1, res2);
```
**7.11:** You have given an array of `nums`. Write a program to `sort` the elements of array in
`descending` order **using built-in** method of array.
```js
Input;
Output[(9, 8, 6, 5, 4, 3, 1)];
```
```js
console.log(result);
```
**7.13:** You have given an array of numbers `nums` You have to check if all elements of the **array >
15** using **built-in** array method. return `true` or `false`
```js
let nums = [16, 17, 18, 28, 22];
```
```js
console.log(result == strArray);
```
**Question 2:** You have **given** two **arrays** below as an example. Your task is to **combine**
them into one By using array method
```js
input;
```
**Question 3:** You have given an array of **letters** below. Convert that array into string of letters
**Without Space**
```js
input;
let arr = ['a', 'b', 'h', 'i', 's', 'h', 'e', 'k'];
output;
('abhishek');
```
```js
console.log(sorted);
```
**Question 5:** Create a function 'calcAverageHumanAge', which accepts an arrays of dog's ages
('ages'), and does the following thing in order:
1. Calculate the dog `age` in human years using the following formula: if the `dogAge <= 2 years` old,
`humanAge = 2 \* dogAg`e. If the `dog is > 2 years` old, `humanAge = 16 + dogAge`
```js
Test data
```
```js
console.log(elem);
```
```js
console.log(result, arr);
```
## Chapter 8 (Date)
### Assignments
```js
console.log(result1, result2);
```
## Chapter 9 (LocalStorage)
### Assignments
**9.1:** Create two variables **myHobby** , **age** . Now **set** their value in local storage
(according to your hobby and age).
After setting also **get** value from local storage and display their values in **console**.
### Assignments
1. Use a **constructor** function to implement a `Bike`. A bike has a `make` and a `speed` property. The
`speed` property is the current speed of the bike in km/h
2. Implement an `accelerate` method that will increase the bike's speed by **50**, and log the new
speed to the console
3. Implement a `brake` method that will decrease the bike's speed by **25**, and log the new speed to
the console
4. Create **2** 'Bike' objects and experiment with calling `accelerate` and `brake` multiple times on
each of them
**Sample Data**
class.
```js
function Person(name) {
this.name = name;
console.log(me.__proto__ == Person.prototype);
console.log(me.__proto__.__proto__ == Object.prototype);
```
**10.4:** Create **constructor** function inside **Car** class with three properties **color** ,
**model** , **company**
```js
class Car {}
```
```js
class Car = {
constructor(){
},
engineMethod = function(){
```
**10.6:** Guess the **Output** and explain Why? And **if** there is any **error** How we can
remove that error?
```js
this.name = name;
this.age = age;
this.brainMethod = function () {
Person.heartMethod = function () {
};
me.brainMethod();
me.heartMethod();
```
**10.7:** Create a new class `Dog` (which will be child class) inherited from `Animal` class. In Addition in
`Dog` class add some additional properties like **breedType**
```js
class Car {
constructor() {}
console.log(Car.prototype.isPrototypeOf(Car));
console.log(Car.prototype.isPrototypeOf(car));
```
```js
car.name = name;
car.model = model;
this.engineMethod = function () {
};
return car;
let constructorObject = {
speak: function () {
},
};
let myCar = carObject('Audi', 2023);
console.log(myCar.__proto__);
```
**Question 2:** You have given an example of **OOP** Code. Your task is to explain the use of `super`
keyword in `Dog` class.
And you have to **change** the code again after removing `super` keyword from the `Dog` class (You
have remove those lines/statements which are not **necessary** after **removing** super
**keyword**)
```js
class Animals {
constructor(name, age) {
this.name = name;
this.age = age;
sing() {
dance() {
super(name, age);
this.whiskerColor = whiskerColor;
whiskers() {
console.log(newDog);
```
**Question 3:** What are the advantages of using **getter** and **setter** method in OOP?
**Question 4:** You have OOP code below. And there is **single** error in this code? Your task is to
**remove that error**.
**Important Note**: To solve this error You need to know about **method chaining** concept.
```js
class Car {
constructor(id) {
this.id = id;
}
setMake(make) {
this.make = make;
setModel(model) {
this.model = model;
setFuelType(fuelType) {
this.fuelType = fuelType;
getCarInfo() {
return {
id: this.id,
make: this.make,
model: this.model,
fuelType: this.fuelType,
};
console.log(
new Car(233)
.setMake('Honda')
.setModel('Civic')
.setFuelType('Petrol')
.getCarInfo()
);
```
**Question 5:** What is difference between ** proto** and prototype property of Object? Try with
**Example**?
Your main task is to add `static` method in that class of your choice ( e.g brainMethod)
```js
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
console.log(me);
```
## Chapter 11( Async Js )
### Assignments
**Html Code**
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript-CoderDost</title>
<style>
</head>
<body>
<div id="content">
</div>
</script>
</body>
</html>
```
**JS Code**
```js
setTimeout(function () {
});
greeting();
```
**11.2:** Find the **Logical Error** in below code. And How can we solve them with **callback**
function approach?
```js
function getMovies() {
setTimeout(() => {
console.log(movie.title);
});
}, 1000);
function createMovies(movie) {
setTimeout(() => {
movies.push(movie);
}, 2000);
}
getMovies();
```
**11.4:** Solve **Question 2** again But this time with the help of **promise**
**11.5:** Now re-factor **Question 2** with the help of **async-await** keyword?
**11.6:** Status code starting with **404** represent which type of message/error?
## Chapter 12 (ES6)
### Assignments
```js
```
```js
console.log(a, b, c, d);
```
```js
let obj = {
name: 'John',
age: 25,
weight: 70,
};
let { name: objName, age } = obj;
console.log(name, age);
```
**12.4:** You have given an array of **nums**.Create **shallow** copy of that array and store them in
another **variable**
```js
```
**12.5:** You have given an array as below . Create a function which accept **multiple** elements as
an argument and return last **4** element of the array
```js
Example:
```
```js
let nums = 0;
console.log(result);
```
**12.7:** You have given an object as below. You have to check wheather **physics** is the subject of
that student or not, if true find the **score** of **physics** subject using **optional chaining**
```js
let student = {
Math: {
score: 75,
},
physics: {
score: 85,
},
};
```
```js
console.log(key);
```
```js
arr1[2] = 10;
console.log(arr, arr1);
```
**Question 2:** You have given a list of variable names written in underscore. You have to write a
program to convert them into camel casing format
```js
Input
user_name
last_name
date_of_birth
user_password
Output
userName
lastName
dateOfBirth
userPassword
```
```js
console.log(`${a} ${b}`);
console.log(c);
console.log(c[0]);
console.log(c.length);
console.log(c.indexOf('google'));
```
```js
```
**Question 5:** Write a program in which you have to set **Default** value in case of false input value
using **Logical Assignment** Operator?
```js
console.log(arr, length);
```
**Question 7:** You have given **Set** below. Your task is to convert that **Set** into an **array**?
```js
input;
output;
```
```js
console.log(result);
```
### Assignments
**13.1:** You have given scenario. You are in **script.js** And in same directory there is another file
**products.js**. In **products.js** there are two methods called **createProduct** and
**deleteProduct**
- write an **import** and **export** statement properly in order to import these two methods from
**products.js** file into the **script.js**
**Question 2** Now **export** only one method **createProduct** using **default** export
statement?