CHAPTERTWO
Be focused and you will archive alot. choose your ON javascript
Explore moreBe focused and you will archive alot. choose your ON javascript
Explore moreLorem ipsum dolor sit amet consectetur adipisicing elit. Hic odit rem dolorum molestiae fugit deserunt exercitationem recusandae, itaque ratione harum sit repellat dolor temporibus deleniti non voluptatem nostrum quas? Cumque veniam, molestias id natus pariatur dolores aut nemo iure facilis expedita, temporibus exercitationem ullam ex officiis reiciendis quaerat enim consequuntur.
Example: Declaring Different Data Types
// String let age = 30;
// Boolean
// Array
JavaScript has different types of data:
Example: Declaring Different Data Types
let name = "Alice"; // String
let age = 30; //Number
let isStudent = true; // Boolean
let colors = ["Red", "Green", "Blue"]; // Array
let person = {
firstName: "John",
lastName: "Doe"
}; // Object
There are two ways to create an object:
* Using an Object Literal {}
* Using the new Object() Constructor
Method 1: Object Literal (Recommended)
let car = {
brand: "Toyota",
model: "Camry",
year: 2022
};
Method 2: Object Constructor (Less Common)
let car = new Object();
car.brand = "Toyota";
car.model = "Camry";
car.year = 2022;
* Dot notation .
* Bracket notation []
Example:
document.write(car.brand); //
Toyota document.write(car["model"]); // Camry Modifying an Object
You can add, update, or delete object properties.
car.color = "Red"; // Add new property car.year = 2023; // Update existing
property delete car.model; // Remove a property
Objects with Methods (Functions inside Objects)
Objects can have functions inside them.
These functions are called methods.
let person = {
name: "Lee Bliss",
greet: function() {
return "Hello, my name is " + this.name;
}
};
document.write(person.greet()); // Output: Hello, my name is Lee Bliss
Try It Out: JavaScript Object in an HTML File
<!DOCTYPE html> <html> <head> <title>Title of thePage</title> </head> <body> <h1>JavaScript Objects</h1> <p id="output"></p> <script> let student = { name: "Alice", age: 20, subjects: ["Math", "Physics", "Computer Science"], greet: function() { return `Hello, my name is ${this.name} and I study ${this.subjects.length} subjects.`; } }; document.getElementById("output").innerHTML = student.greet(); </script> </body> </html>
Title of thePage
JavaScript Objects
vildash network team has had alot of impact on others but here are the vildash network team testimonies and expirience while working with the team
you can now connect and text other users from our database. you just neeed to click bellow to message them
WE HAVE CODE EDITORS FOR LANGUAGES LIKE C, C#, C++, HTML, CSS, javascript, JAVA VISUAL BASIC
We dont just teach you to code we teach you to code and build amazing systems.we are group of expert who wants to promote our field of studies