Tuesday, February 10, 2026

Full Stack Development - Objects and Methods- class 9

 Methods are actions that can be performed on objects.

Methods are functions stored as property values.

In JavaScript, objects are collections of related properties (data) and methods (functions that perform actions).

Objects
Objects are a fundamental data type in JavaScript used to store complex entities and collections of key-value pairs.
Properties are named values that define the characteristics or state of an object (e.g., a person's name or age). They are stored as key-value pairs.
  • Methods are functions stored as property values that define the behaviors or actions an object can perform (e.g., a person walk() or talk()).
  • Nearly all objects in JavaScript inherit properties and methods from Object.prototype
Built-in Object Methods
JavaScript provides numerous built-in methods on the global Object constructor that allow you to work with objects. These are static methods used directly on the Object constructor itself, rather than an object instance.
  • Object.keys(obj): Returns an array of an object's own enumerable string property names.
  • Object.values(obj): Returns an array containing the values of an object's own enumerable string properties.
  • Object.entries(obj): Returns a nested array of an object's own enumerable string key-value pairs.
  • Object.assign(target, source): Copies all enumerable own properties from one or more source objects to a target object.
  • Object.create(proto): Creates a new object with the specified prototype object and properties.
  • Object.freeze(obj): Prevents any extensions of an object and makes existing properties non-writable.
  • Object.seal(obj): Prevents new properties from being added, but allows modification of existing properties.

const person = {

  firstName: "John",
  lastName: "Doe",
  age: 50,
  fullName: function() {
    return this.firstName + " " + this.lastName;
  }
};
person.function(); => gives the first name

const objectMethod =function(){

                        console.log("name:"+this.name);                        console.log("RegNo:"+this.regNo);                        console.log("NetWOrth:"+this.netWorth);

                    }

        const obj ={name: "Dhanush BS",
                    regNo: "1JT23IS016",
                    netWorth: "$1000000",
                    display:objectMethod,
        }
        const obj2 ={name: "Yashwanth S D",
                    regNo: "1JT23IS064",
                    netWorth: "$10000000",
                    display:objectMethod,
        }
        obj.display();
        obj2.display();

This keyword:

const person = {
  firstName: "John",
  lastName: "Doe",
  id: 5566,
  getId: function() {
    return this.id;
  }
};

let number = person.getId();

In the example above, this refers to the person object.

this.id means the id property of the person object.

person.name = function () {
  return (this.firstName + " " + this.lastName).toUpperCase();
};

Nested Objects

myObj = {
  name:"John",
  age:30,
  myCars: {
    car1:"Ford",
    car2:"BMW",
    car3:"Fiat"
  }
}

console.log(myObj.myCars.car2)

JavaScript Destructuring

let {firstName, lastName} = person;

It can also unpack arrays and any other iterables:

let [firstName, lastName] = person;

// Create an Object
const person = {
  firstName: "John",
  lastName: "Doe",
  age: 50
};

// Destructuring
let {firstName, lastName} = person;

The order of the properties does not matter:

// Destructuring
let {lastName, firstName} = person;

JavaScript Object Prototypes


All JavaScript objects inherit properties and methods from a prototype.


In the previous chapter we learned how to use an object constructor:

Example

function Person(first, last, age, eyecolor) {
  this.firstName = first;
  this.lastName = last;
  this.age = age;
  this.eyeColor = eyecolor;
}

const myFather = new Person("John""Doe"50"blue");
const myMother = new Person("Sally""Rally"48"green");

We also learned that you cannot add a new property to an existing object constructor:

Example

Person.nationality = "English";

To add a new property to a constructor, you must add it to the constructor function:

Example

function Person(first, last, age, eyecolor) {
  this.firstName = first;
  this.lastName = last;
  this.age = age;
  this.eyeColor = eyecolor;
  this.nationality = "English";
}

Sunday, February 8, 2026

Full Stack Development - js Functions - class 8

 Js functions are a section of reusable code. Declare it once and use it wherever you want. Call the function to execute that code.

function happyBirthday(){

    console.log("Happy birthday to you!");

    console.log("Happy birthday to you!");

  console.log(`Happy birthday dear ${username}!`);

   console.log("Happy birthday to you!");

   console.log(`You are ${age} years old!`);

}

function checkValidEmail(email)

{

   return email.includes("@") ;

}

happyBirthday();

console.log(checkValidEmail("fakeemail@fakesite.com"));

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

https://www.w3schools.com/js/js_functions.asp

1. Assigned to a variable (Function Expression)
You can store an anonymous function in a variable, which then acts as the function's identifier for calling it later.
const greet = function() { console.log("Hello!"); }; greet(); // Output: Hello!

let x = 10;
let y = 20;
let z = (x,y)=> {return x + y;}
console.log(z(2,3));
2. As an argument (Callback Function)
They are commonly passed as arguments to higher-order functions like setTimeout()map()filter(), or event handlers.

Thursday, February 5, 2026

Full Stack Development - Class 7- Strings Continued

 JavaScript String charAt()

let text = "HELLO WORLD";
let char = text.charAt(0);

JavaScript String charCodeAt()

let text = "HELLO WORLD";
let char = text.charCodeAt(0);

JavaScript codePointAt()

let text = "HELLO WORLD";
let code = text.codePointAt(0);

JavaScript String at()

const name = "W3Schools";
let letter = name.at(2);
Get the third letter of name
const name = "W3Schools";
let letter = name[2];
Immutable
let text = "HELLO WORLD";
text[0] = "A";    // Gives no error, but does not work

JavaScript String concat()

let text1 = "Hello";
let text2 = "World";
let text3 = text1.concat(" ", text2);

Note

All string methods return a new string. They don't modify the original string.

Formally said:

Strings are immutable: Strings cannot be changed, only replaced.

Extracting String Parts

There are 3 methods for extracting a part of a string:

  • slice(startend)
  • substring(startend)
  • substr(startlength)
let text = "Apple, Banana, Kiwi";
let part = text.slice(713);

let text = "Apple, Banana, Kiwi";
let part = text.slice(7);

let text = "Apple, Banana, Kiwi";
let part = text.slice(-12);

let text = "Apple, Banana, Kiwi";
let part = text.slice(-12, -6);

JavaScript String substring()

let str = "Apple, Banana, Kiwi";
let part = str.substring(713);