Ai Vehicle traffic signal detector Literature Review.DavidNameza
Ad
Web creation languages : Jason Learn Jason
2. JSON - JavaScript Object Notation is a lightweight data-interchange format that is easy for
humans to read and write and easy for machines to parse and generate.
Syntax:
JSON syntax is derived from JavaScript object notation syntax:
Data Types: JSON supports primitive data types like strings, numbers, booleans, and null,
as well as complex data types like arrays and objects.
Format: Data is represented in key-value pairs. Keys must be strings enclosed in double
quotes, and values can be any valid JSON data type.
https://youtu.be/iiADhChRriM?si=y_whC20WOnxNDjco
Introduction to JSON
5. Data Format
Text-Based: JSON data is stored as plain text, making it easy to transmit
and store.
Hierarchy: Supports nested structures using arrays and objects,
allowing complex data relationships to be represented.
Platform Independence: Widely supported across programming
languages and platforms, making it ideal for interoperability.
6. Use Cases:
JSON is commonly used for:
APIs: Many web APIs use JSON for data interchange between servers and
clients.
Configuration Files: Often used for configuration settings due to its
simplicity and readability.
Data Storage: Storing and transmitting structured data in web applications
and databases.
Serialization: Converting objects into JSON format for transmission or
storage, and deserialization vice versa.
JSON's simplicity, readability, and flexibility make it a popular choice for
exchanging data between systems and applications on the web.
7. Creating JSON objects in JavaScript involves defining and structuring
data using JavaScript syntax, which closely resembles the JSON format
itself. Here’s how you can create and manage JSON objects, including
nesting and handling complex data structures:
JSON Objects
8. Basic JSON Object Creation:
You can create a JSON object directly in JavaScript by
defining it as a JavaScript object literal enclosed in curly
braces { }
// Define a JSON object
let person = {
"name": "John Doe",
"age": 30,
"isStudent": false,
"courses": ["Math", "Science"],
"address": {
"city": "New York",
"zipCode": "10001"
}
};
console.log(person);
9. Managing Nesting:
JSON supports nested objects and arrays, allowing you to
represent hierarchical data structures
// Nested JSON object
let nestedObject = {
"name": "John Doe",
"contacts": [
{
"type": "email",
"value": "[email protected]"
},
{
"type": "phone",
"value": "123-456-7890"
}
],
"address": {
"city": "New York",
"zipCode": "10001"
}
};
10. Dynamically Creating JSON:
You can dynamically add properties and values to a JSON object using
JavaScript’s object notation
// Dynamic JSON creation
let dynamicObject = {};
dynamicObject.name = "Jane Smith";
dynamicObject.age = 25;
dynamicObject.skills = ["JavaScript",
"HTML", "CSS"];
dynamicObject.address = {
"city": "San Francisco",
"zipCode": "94105"
};
console.log(dynamicObject);
11. Complex Data Structures:
JSON in JavaScript can handle complex data structures such as arrays of
objects or nested objects within arrays
// Complex JSON structure
let complexData = {
"employees": [
{
"name": "Alice",
"department": "Engineering",
"skills": ["JavaScript", "Python"]
},
{
"name": "Bob",
"department": "Marketing",
"skills": ["SEO", "Social Media"]
}
],
"company": {
"name": "TechCo",
"location": "San Francisco"
}
};
console.log(complexData);
12. Stringification
To convert a JavaScript object into a JSON string for transmission or
storage, use
JSON.stringify():
let jsonString =
JSON.stringify(complexData);
console.log(jsonString);
13. Parsing JSON:
To convert a JSON string back into a JavaScript object, use
JSON.parse():
let parsedObject = JSON.parse(jsonString);
console.log(parsedObject);
This covers the basics of creating, managing nesting, and handling complex data
structures with JSON objects in JavaScript, essential for web development and data
interchange scenarios.
14. Document Object Model (DOM) Manipulation
The DOM is:
Structured Representation: It represents the structure of a document as a tree of
objects, where each object corresponds to a part of the document.
Platform- and Language-Neutral: It provides a platform-neutral and language-neutral
interface, meaning it allows programs and scripts to dynamically access and update
the content, structure, and style of documents.
Dynamic: It allows JavaScript and other scripting languages to interact with the
structure and content of web pages, enabling dynamic updates and changes without
needing to reload the entire page.
Hierarchy: Elements in the document (such as elements, attributes, and text) are
organized in a hierarchical tree structure. Each node in the tree represents an object
corresponding to a part of the document.
15. DOM Manipulation:
DOM manipulation refers to the process of accessing or modifying
elements within the DOM tree using programming languages like
JavaScript. Developers commonly use DOM manipulation to
Update Content: Change text or attributes of elements.
Modify Structure: Add or remove elements dynamically.
Respond to Events: Attach event listeners to elements to respond to user
actions (e.g., clicks, inputs).
Animate Elements: Change CSS styles or properties to create animations
or transitions.
16. Example:
A basic example of how DOM manipulation works in JavaScript
<!DOCTYPE html>
<html>
<head>
<title>DOM Manipulation Example</title>
<script>
// JavaScript for DOM manipulation
document.addEventListener("DOMContentLoaded", function() {
// Find an element by id
let header = document.getElementById("main-header");
// Change its text content
header.textContent = "Updated Header";
// Create a new element
let newParagraph = document.createElement("p");
newParagraph.textContent = "This is a new paragraph.";
// Append it to the document
document.body.appendChild(newParagraph);
});
</script>
</head>
<body>
<h1 id="main-header">Original Header</h1>
</body>
</html>
17. In this example:
JavaScript accesses the <h1> element with id="main-header".
It changes the text content of this element.
It creates a new <p> element and appends it to the <body> of the document.
DOM manipulation is fundamental for creating interactive web
pages and web applications, allowing developers to dynamically
update and interact with page content based on user actions or
application logic.
18. Event Handling:
Adding Event Listeners:
Use addEventListener() method to attach event handlers to elements.
Syntax: element.addEventListener(eventType, handlerFunction);
const button =
document.getElementById('myButton');
button.addEventListener('click',
function(event) {
// Handle click event
});
Handling Events:
Common events include click, submit, keypress, etc.
Each event type triggers specific actions or behaviours.
19. Event Object and Event Propagation:
Accessing Event Properties:
Use the event object to access information about the event.
Example properties: event.target, event.preventDefault(), event.stopPropagation().
Understanding Event Propagation:
Event Bubbling: Events bubble up from the target element through
its ancestors.
Event Capturing: Events propagate down from the document root
to the target element.
20. AJAX (Asynchronous JavaScript and XML)
Introduction to AJAX:
Asynchronous Nature of JavaScript Requests:
Allows web pages to dynamically update content without reloading the entire page.
Enhances user experience by providing smoother and faster interactions.
Evolution from Traditional Synchronous Requests:
Traditional synchronous requests block the browser until the request completes.
AJAX enables asynchronous requests, allowing other operations to continue while waiting
for the response.
XMLHttpRequest Object:
Creating and Configuring XMLHttpRequest:
Core object for making asynchronous requests in JavaScript.
Methods: open(), send(), abort().
https://youtu.be/tNKD0kfel6o?si=OHECiO6EWKXb24er
21. Example
let xhr = new XMLHttpRequest();
xhr.open('GET', 'data.json', true);
xhr.send();
Sending GET and POST Requests:
GET requests retrieve data from a server.
POST requests send data to a server for processing.
22. Fetch API:
Modern Approach to AJAX with Fetch API:
Simplifies fetching resources asynchronously.
Returns a Promise that resolves to the response to the request.
Example:
fetch('data.json')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error fetching data:', error));
Handling JSON Responses and Error Management:
Fetch API automatically parses JSON responses.
Handle errors using .catch() to manage network issues or failed requests.
23. Handling AJAX Responses
Using Callbacks, Promises (then, catch), and async/await:
Callbacks: Traditional approach for handling asynchronous operations.
Promises: Provides cleaner syntax for chaining asynchronous operations (then, catch).
Async/Await: Modern ES8 feature for synchronously writing asynchronous code.
Examples of Retrieving and Displaying Data Asynchronously:
Demonstrate fetching data from an API and updating the DOM dynamically based on the retrieved
data.
Editor's Notes
#22: Handling JSON Responses and Error Management:
Fetch API automatically parses JSON responses.
Handle errors using .catch() to manage network issues or failed requests.