JavaScript Built-in Objects (PDF)

Document Details

BetterThanExpectedLearning9144

Uploaded by BetterThanExpectedLearning9144

Yeungjin University

Richard Canapi

Tags

javascript built-in objects web development programming javascript dom

Summary

This document provides a detailed explanation of JavaScript built-in objects, including the Document Object Model (DOM) and Browser Object Model (BOM). It discusses concepts, properties, methods, and examples for common objects like the Date and Math objects.

Full Transcript

**Concept of Built-in Object** **Understanding of JavaScript Objects** \- Objects in JavaScript are containers for Properties and Methods. \- Properties are named Values and Methods are Functions stored as Properties. **Concept of Built-in Object** *** Built-in Object*** ** Built-in Object -...

**Concept of Built-in Object** **Understanding of JavaScript Objects** \- Objects in JavaScript are containers for Properties and Methods. \- Properties are named Values and Methods are Functions stored as Properties. **Concept of Built-in Object** *** Built-in Object*** ** Built-in Object - The Document Object Model (DOM)** \- We can also add events to these elements to make our page more dynamic. ![](media/image2.png) ** Built-in Object - The Browser Object Model (BOM)** \- The Browser Object Model (BOM) allows JavaScript to \"talk to\" the browser. \- The BOM includes objects such as Window, Navigator, Location, History, and Screen. A diagram of a computer Description automatically generated **The Standard built-in objects** **JavaScript Math Object** ** Math Properties (Constants)** -The syntax for any Math property is : Math.property. -JavaScript provides 8 mathematical constants that can be accessed as Math properties. ![A screenshot of a computer Description automatically generated](media/image4.png) ** Math Methods** -The syntax for Math any methods is : Math.method(number) -There are 4 common methods to round a number to an integer. A screenshot of a computer Description automatically generated ** Concept and Examples of Date Object** \- The Date object represents dates and times in JavaScript. ![A screenshot of a computer program Description automatically generated](media/image6.png) ** Creating Date Objects** -Date objects are created with the new Date() constructor. -There are 9 ways to create a new date object: A white background with black text Description automatically generated ** Date Methods** \- When a date object is created, a number of methods allow you to operate on it. ** Date Get Methods** -The get methods return information from existing date objects. ![A screenshot of a computer program Description automatically generated](media/image8.png) ** Date Set Methods** A screenshot of a phone Description automatically generated ** Date Set Methods** -Dates can easily be compared. -The following example compares today\'s date with January 14, 2100: ![A screenshot of a computer Description automatically generated](media/image10.png) **JavaScript String Object** ** Concept and Examples of String Object** A screenshot of a computer program Description automatically generated ** String Length Properties** -To find the length of a string, use the built-in length property. ![A computer code with black text Description automatically generated with medium confidence](media/image12.png) ** Date String Methods** \- JavaScript strings are primitive and immutable \- All string methods produce a new string without altering the original string. A screenshot of a computer program Description automatically generated ** Arrays are Objects** \- Arrays are a special type of objects. \- The typeof operator in JavaScript returns \"object\" for arrays. \- But JavaScript arrays are best described as arrays. \- Arrays use indexes to access it's \"elements\". ![A white board with red green and blue text Description automatically generated](media/image14.png) ** Arrays are Objects** \- JavaScript has a built-in array constructor new Array(). \- But you can safely use \[\] instead. \- These two different statements both create a new empty array named points. A screenshot of a computer code Description automatically generated ** Arrays are Objects** -Objects use Keys to access its \"elements\". ![A screenshot of a computer program Description automatically generated](media/image16.png) ** Array Elements Can Be Objects** \- JavaScript variables can be objects. Arrays are special kinds of objects. \- Because of this, you can have variables of different types in the same Array. \- You can have objects and functions in an Array. - You can have arrays in an Array A white rectangular object with a black border Description automatically generated ** Array Properties and Methods** \- The real strength of JavaScript arrays are the built-in array properties and methods. \- The length property of an array returns the length of an array (the number of array elements). \- The easiest way to add a new element to an array is using the push() method: ![A close-up of a computer code Description automatically generated](media/image18.png) **Array Properties and Methods** A screenshot of a computer program Description automatically generated ** Looping Array Elements** -One way to loop through an array, is using a for loop. ![A screenshot of a computer code Description automatically generated](media/image20.png) **Learning Summary** **1. Concept of Built-in Object** \- Objects in JavaScript are containers for Properties and Methods. **2. The Standard built-in objects** \- The JavaScript Math object allows you to perform mathematical tasks on numbers. \- The Date object represents dates and times in JavaScript. \- JavaScript has a built-in array constructor new Array().

Use Quizgecko on...
Browser
Browser