Saturday, December 30, 2023

Day 21 || Setting up development environment || CRA || Create React App || npx create-react-app || Folder structure || Entry point in react.js App

 React.js Topics

Day 21:

  • Setting up development environment
    • CRA : Create React App
    • Folder structure
    • Entry point
CRA:

How to create React app using CRA?
  • npx create-react-app <app Name>
How to run React Application ?
  • npm start
How to stop React Application ? 
  • Ctrl + c

Folder structure:

Node_Modules
Public
  • Index.html
Src
  • App.css
  • App.js
  • Index.css
  • Index.js
Package.json
Package-lock.json


Entry point:

npm start => package.json (configuration and dependencies) => Webpack and Babel bundle (transform and bundle code) => index.js (entry point) => index.html (HTML template with injected bundled code).

Interview Questions:

1. How does CRA handle Webpack and Babel configuration?

2. What is the purpose of the npm start command in a Create React App project?

3. what is difference between npm and npx

Friday, December 29, 2023

Day 20 || Rules of JSX || Components and Props in React js

React.js Topics

Day 20:

  • Rules of JSX
  • Components and Props

Rules of JSX: 



















ReactWithCDNLinks.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script
      crossorigin
      src="https://unpkg.com/react@18/umd/react.development.js"
    ></script>
    <script
      crossorigin
      src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
    ></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
  </head>
  <body id="root">
    <script type="text/babel">
      function reactReuse(name, age, img) {
        return (
          <div
            style={{
              width: "250px",
              textAlign: "center",
              boxShadow: "0 0 10px black",
              padding: "10px",
            }}
          >
            <img src={img} alt="TATA" width="100%" height="300px" />
            <h2>{name}</h2>
            <p>{age}</p>
          </div>
        );
      }
      function reactCall() {
        return (
          <div style={{ display: "flex", justifyContent: "space-between" }}>
            {reactReuse(
              "Rathan TATA",
              86,
              "https://assets.gqindia.com/photos/645e034efc79052643f24e8e/16:9/w_1920,c_limit/Ratan-Tata.jpg"
            )}
            {reactReuse(
              "Sundar Pichai",
              51,
              "https://sugermint.com/wp-content/uploads/2020/04/Biography-of-Sundar-Pichai.jpg"
            )}
            {reactReuse(
              "Nadella Satya",
              56,
              "https://akm-img-a-in.tosshub.com/indiatoday/images/story/202306/rtx6otlw-sixteen_nine.jpg?VersionId=G9LYYNj7sPJp7BvqwTUD95L69H74FjNB&size=690:388"
            )}
            {reactReuse(
              "Jaya Varma Sinha",
              60,
              "https://sambadenglish.com/wp-content/uploads/2023/08/Jaya-Verma-Sinha-e1693478762805.jpg"
            )}
          </div>
        );
      }
      ReactDOM.render(reactCall(), document.getElementById("root"));
      reactCall();
    </script>
  </body>
</html>


Components and Props:
ComponentAndProps.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script
      crossorigin
      src="https://unpkg.com/react@18/umd/react.development.js"
    ></script>
    <script
      crossorigin
      src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
    ></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
  </head>
  <body id="root">
    <script type="text/babel">
      function ReactReuse(props) {
        return (
          <div
            style={{
              width: "250px",
              textAlign: "center",
              boxShadow: "0 0 10px black",
              padding: "10px",
            }}
          >
            <img src={props.img} alt="TATA" width="100%" height="300px" />
            <h2>{props.name}</h2>
            <p>{props.age}</p>
          </div>
        );
      }
      function ReactCall() {
        return (
          <div style={{ display: "flex", justifyContent: "space-between" }}>
            <ReactReuse
              name="Rathan TATA"
              age={86}
              img="https://assets.gqindia.com/photos/645e034efc79052643f24e8e/16:9/w_1920,c_limit/Ratan-Tata.jpg"
            />

            <ReactReuse
              name="Sundar Pichai"
              age={51}
              img="https://sugermint.com/wp-content/uploads/2020/04/Biography-of-Sundar-Pichai.jpg"
            />
            <ReactReuse
              name="Nadella Satya"
              age={56}
              img="https://akm-img-a-in.tosshub.com/indiatoday/images/story/202306/rtx6otlw-sixteen_nine.jpg?VersionId=G9LYYNj7sPJp7BvqwTUD95L69H74FjNB&size=690:388"
            />
            <ReactReuse
            name="Jaya Varma Sinha"
            age={60}
            img="https://sambadenglish.com/wp-content/uploads/2023/08/Jaya-Verma-Sinha-e1693478762805.jpg"
            />
          </div>
        );
      }
      ReactDOM.render(<ReactCall/>, document.getElementById("root"));
     
    </script>
  </body>
</html>


Interview Questions:

1. How do you embed JavaScript expressions in JSX?

2. What is a React component?

3. How do you access props in a functional component?








Monday, December 25, 2023

Day 19 || Introduction of React || Integration of React into an HTML structure || Including React and React DOM from CDN Links || JSX

  React.js Topics

Day 19:

  • Introduction of React.js
  • Integration of  React into an HTML structure
    • Including React from CDN Links
    • Including React DOM from CDN Links
  • JSX

Including React from CDN Links :













Including React DOM from CDN Links :








 




JSX: 














ReactWithCDNLinks.html: 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script
      crossorigin
      src="https://unpkg.com/react@18/umd/react.development.js"
    ></script>
    <script
      crossorigin
      src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
    ></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
  </head>
  <body id="root">
    <script type="text/babel">
      //   let h1Tag = React.createElement(
      //     "h1",
      //     { id: 1, style: { color: "red" } },
      //     "Welcome to Hema coding school",
      //     [
      //       React.createElement(
      //         "p",
      //         null,
      //         "Your presence is very important to us"
      //       ),
      //       React.createElement("div", null, "However, guests are limited"),
      //     ]
      //   );
      function reactReuse() {
        let h2TagJSX = (
          <h1 id="1" style={{ color: "blue" }}>
            Welcome to Hema coding school
            <p>Your presence is very important to us</p>
            <div>However, guests are limited</div>
          </h1>
        );
        return h2TagJSX;
      }
      function reactCall() {
        let functionCall = (
          <div>
            {reactReuse()}
            {reactReuse()}
            {reactReuse()}
            {reactReuse()}
          </div>
        );
        ReactDOM.render(functionCall, document.getElementById("root"), () => {
          alert("Rendered successfully");
        });
      }
      reactCall();
    </script>
  </body>
</html>



Interview Questions:  

1. What is the role of React.createElement in integrating React into an HTML structure?

2. Why might you choose to include React and React DOM from CDN links instead of installing them locally?

3. Explain how JSX gets transpiled into JavaScript and why this step is necessary.

4 .Walk through the process of rendering a React element into the DOM using ReactDOM.render


Saturday, December 23, 2023

Day 18 || Module in Node.js || Export in JavaScript || Import in JavaScript

 JavaScript Topics

Day 18:

  • Module
    • Export
    • Import

  • Page Creation

export.mjs

// ==================Node.js============
let greeting = "Hello";
let name = "Hema";

let sayHello = () => {
  return `${greeting} ${name}, How are you?`;
};

module.exports = { sayHello };


//===================== ES6 ===============
export function sayGreeting() {
  return "Hello Hema, what's going on";
}


import.mjs

// ==================Node.js============

let myCall = require('./export.js');
console.log(myCall.sayHello())

//===================== ES6 ===============

import { sayGreeting } from "./export.mjs";
console.log(sayGreeting());


StudentInfo.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="./Home.css" />
    <link rel="stylesheet" type="text/css" href="./StudentInfo.css" />
  </head>
  <body>
    <header>
      <h1>Hema Coding School</h1>
    </header>
    <nav>
      <a href="./Home.html">Home</a>
      <a href="./Courses.html">Courses</a>
      <a href="./About.html">About Us</a>
      <a href="./Contact.html">Contact</a>
      <a href="./StudentInfo.html">Student Information</a>
    </nav>
    <main>
        <section>
            <marquee >Welcome to Hema Coding School</marquee>
        </section>
        <section>
            <h2>Student Information</h2>
            <table id="studentInfoTable">
                <thead>
                    <tr>
                        <th>S. No</th>
                        <th>Name</th>
                        <th>Attendance</th>
                        <th>Feedback</th>
                    </tr>
                </thead>
                <tbody id="studentInfoBody">

                </tbody>
            </table>
        </section>
    </main>
    <footer>
        <p>&copy; 2024 Hema Coding School. All rights reserved.</p>
    </footer>
    <script src="./StundentInfo.js"></script>
  </body>
</html>



StudentInfo.css:

table {
  width: 100%;
  margin-top: 1em;
}
table,th,td{
    border: 1px solid #ddd;
}
th{
    background-color: #efdcdc;
}
th,td{
    padding: 0.8em;
    text-align: center;
}


StundentInfo.js:

const students = [
    { id: 1, name: "Hema", attendance: 80, feedback: "Excellent" },
    { id: 2, name: "Mahesh", attendance: 75, feedback: "Good" },
    { id: 3, name: "Maruthi", attendance: 90, feedback: "Very Nice" },
  ];

  let displayStudents = () => {
    let studentInfoBody = document.getElementById("studentInfoBody");
    students.map((student) => {
      console.log(student.name);

      let row = document.createElement('tr');
      row.innerHTML = `<td>${student.id}</td><td>${student.name}</td><td>${student.attendance}%</td><td>${student.feedback}</td>`
      studentInfoBody.appendChild(row)

    });
  };
 
    let addStudent = (id, name, attendance, feedback)=>{
        let studentData = students.push({id, name, attendance, feedback})
    }
    addStudent(4, "Riya", 95, "Out Standing");
    addStudent(5, "Rathan", 85, "Very Good");
    addStudent(6, "Girija", 95, "Outstanding");

  displayStudents()



Interview Questions:

1. What is the purpose of the export statement in JavaScript?
2. How do you use the export statement to export a variable or function?
3. Explain the difference between named exports and default exports?







Friday, December 22, 2023

Day 17 || Call Back Function || Array Methods in JavaScript || map || filter || reduce || map vs filter vs reduce in JavaScript

JavaScript Topics

Day 17:

  • Call Back Function
  • Array Methods
    • Map(),
    • Filter(),
    • Reduce()

Call Back Function:

function name(x) {
  console.log("Hema");
  role();
}

function role() {
  console.log("Student");
}

name(role);

let name = (x)=> {
    console.log("Hema");
    role();
  }
 
  let  role = ()=> {
    console.log("Student");
  }
 
  name(role);


Array Methods:

let originalArray = [1, 2, 3, 4, 5];

let newArray = originalArray.map((currValue, ind, arr) => {

//   console.log(currValue * 2);
    return currValue % 2 === 0
});

console.log(newArray);

let originalArray = [1, 2, 3, 4, 5];
let multiply = {
  number: 2,
};

let newArray = originalArray.map(function(currValue, ind, arr) {
//   console.log(currValue * this.number);
  return currValue * this.number;
}, multiply);

console.log(newArray);
let originalArray = [1, 2, 3, 4, 5];

let filterArray = originalArray.filter((currValue, ind, arr) => {
  return currValue % 2 === 0;
});

console.log(filterArray);

let originalArray = [6, 1, 2, 3, 4, 9, 5, 6, 8, 7];

let reduceArray = originalArray.reduce((acc, currValue, ind, arr) => {
    return acc + currValue;
});

console.log(reduceArray);


let originalArray = [1, 2, 3, 4, 5];

let newArray = originalArray.map((currValue, ind, arr) => currValue * 3);
console.log(newArray);

let evenNumber = newArray.filter((currValue) => currValue % 2 === 0);
console.log(evenNumber);

let singleValue = evenNumber.reduce((acc, currValue) => acc + currValue);
console.log(singleValue);
let newArray = originalArray
  .map((currValue, ind, arr) => currValue * 3)
  .filter((currValue) => currValue % 2 === 0)
  .reduce((acc, currValue) => acc + currValue);
console.log(newArray);


Tasks:

Task 1: Call Back
Write a function calculate that takes two numbers and a callback function as arguments. The callback function should perform a mathematical operation (addition, subtraction, multiplication, or division) on the two numbers.

Task 2: Map + Filter
Given an array of words, create a new array that contains the lengths of words that have more than three characters.
const words = ['apple', 'banana', 'pear', 'grape', 'kiwi'];

Task 3: Map + Reduce
Given an array of numbers, create a new array that contains the square of each number and then calculate the sum of the squared values.
const numbers = [1, 2, 3, 4, 5];

Interview Questions:

1. Why are callback functions useful in JavaScript?
2. What is the difference between using map and a for loop for iterating over an array?
3. How does the filter method differ from the map method?
4. Explain the concept of the reduce method in JavaScript?






Thursday, December 21, 2023

Day 16 || Arrow function in JavaScript

 JavaScript Topics

Day 16:

  • Arrow Function

ArrowFunction:

// 1. Syntax

function traditionalFunction(x, y) {
  return x + y;
}
// console.log(traditionalFunction(2, 3));

let arrowFunction = (x, y) => {
  return x + y;
};

// console.log(arrowFunction(2,3))

// 2. this binding

let user = {
  name: "Hema",
  sayNamaste: function () {
    console.log("Namaste " + this.name);
  },

  sayHello: () => {
    console.log("Hello " + this.name);
  },
};

// user.sayNamaste()
// user.sayHello()

// 3. Arguments Object
function printArguments() {
  for (i = 0; i < arguments.length; i++) {
    console.log(arguments[i]);
  }
}
// printArguments(1, 2, 3, 4, 5);

let printArgumentsA = (...arguments) => {
  for (i = 0; i < arguments.length; i++) {
    console.log(arguments[i]);
  }
};

// printArgumentsA(1, 2, 3, 4, 5);

// 4. Return

function multiply(x,y){
    return x*y;
}
console.log(multiply(2,3))

let multiplyA =(x,y)=> x * y;
console.log(multiplyA(4,5))


Task:

Task 1: Arrow Function with Parameters

Write an arrow function called calculateArea that takes the radius of a circle as a parameter and returns the area of the circle. Use the formula: Area=×radius2. Assume that π (pi) is approximately 3.14.

Task 2: Arrow Function with a Default Parameter

Write an arrow function called power that takes two parameters: a base (x) and an exponent (y). If no exponent is provided, default it to 2. The function should return the result of raising the base to the exponent.

Interview Questions:

1. How do arrow functions differ from regular functions in terms of syntax and behavior?

2. Explain the concept of lexical scoping and how it applies to arrow functions.

3. What is the main advantage of using arrow functions over traditional functions?


Top 10 | JavaScript Coding Interview Question | Beginner Level

               JavaScript Coding Interview  Q. No. 01/10:  console . log ( "1" + "4" + "1" ) // 141 console . ...