[Go to site: main page, start]

0% found this document useful (0 votes)
2 views42 pages

JavaScript Object Concepts and Tasks

Uploaded by

masoomfatima1213
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views42 pages

JavaScript Object Concepts and Tasks

Uploaded by

masoomfatima1213
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Script

By Shahbaz Ashraf
Week 5
Objects (Part-A)
Java Script
Object’s Concepts and Tasks-To-Do (Part A)
• Object Creation
• Create an object called person with properties such as name, age, city, and
email. Fill in the values with your own information.
Object’s Concepts and Tasks-To-Do (Part A)
• Write JavaScript code to access and display the name and age
properties of the person object.
Object’s Concepts and Tasks-To-Do (Part A)
• Add a method called greet to the person object. The greet method
should display a greeting message using the name property
Object’s Concepts and Tasks-To-Do (Part A)
• Create an object called student with properties like name, age, grade,
and subjects (an array of subjects the student is enrolled in). And now
use a “for...in” loop to iterate through the properties of the student
object and display them.
Object’s Concepts and Tasks-To-Do (Part A)
• Add a new property to the person object called phoneNumber. Set it
to your phone number. Update the age property of the person object
to reflect your current age.
Object’s Concepts and Tasks-To-Do (Part A)
• Create two objects, book1 and book2, each with properties like title, author, and year. Make sure
they have some similar properties and some different ones. Write a function that compares these
two objects and checks if they are equal (have the same properties and values).
Week 6
Objects (Part-B)
Java Script
Object’s Concepts and Tasks-To-Do (Part B)
• Nested Objects:
• Create an object called school with
properties like name, location, and
students.
• The student’s property should be
an array of student objects (similar
to the student object you created
earlier).
• Write code to access and display
the information of a specific
student within the school object.
Object’s Concepts and Tasks-To-Do (Part B)
• Object De-structuring:
• Given an object with properties like firstName, lastName, and email, use
object destructuring to extract and display these properties.
Object’s Concepts and Tasks-To-Do (Part B)
• Object Serialization:
• Convert the person object into a JSON string using [Link]().
• Then, parse the JSON string back into an object using [Link]().
Object’s Concepts and Tasks-To-Do (Part B)
• Object Cloning:
• Create a new object called personCopy and copy the properties of the person
object into it. Ensure that personCopy is a separate object and any changes
made to one object do not affect the other.
Week 7+8
Arrays (Complete)
Java Script
For variable size, based on input values

var a= new Array(5);


For fix size
Note: Try all methods on an array (String or Integer)
Sanjay
Note: Try all methods on an array (String or Integer)
And so on…
Home Task -> Try all Methods
Week 9
Callbacks
Java Script
• Callbacks
• Simple Callback Function
• Create a function called sendMessage that takes a message and a callback
function as parameters. The function should call the callback function with
the message.
• Callbacks
• Error Handling with
Callbacks:
• Modify the
sendMessage function
from the first exercise
to introduce error
handling.
• If an error occurs, call a
different callback
function to handle the
error.
Week 10
Promises
Java Script
Promises
• Promises are widely used for tasks like making network
requests, reading/writing files, and other operations that
don't block the main thread.
• A promise represents a value that may not be available yet
but will be resolved at some point in the future It can be in
one of three states:
• Pending,
• Fulfilled, or
• Rejected.
• Once a promise is fulfilled or rejected, it's considered settled
and its state cannot change.
Callback Promisify:
• Take a callback-based function (e.g., [Link] for reading a file) and create a
Promise-based version of it using a custom function.


Week 11
Async/Await
Java Script
• Async/Await
• Callback Hell (Callback Pyramid):
• Create a series of nested callback
functions to simulate a callback hell
scenario.
• For example, you can simulate
asynchronous operations like fetching
user data, their posts, and comments on
each post, all nested within callbacks.
Async/Await
• Parallel Callback Execution:
• Create an array of functions that simulate asynchronous tasks.
• Use a loop and callbacks to execute all tasks in parallel and collect the results in
an array.

You might also like