Skip to content

Commit 93d412d

Browse files
committed
feat: updated
1 parent 5908dca commit 93d412d

File tree

1 file changed

+249
-28
lines changed

1 file changed

+249
-28
lines changed

README.md

Lines changed: 249 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ Document Object Model
20062006
20072007
| Property | Description | DOM |
20082008
|--|--|--|
2009-
| document.anchors | Returns all elements that have a name attribute | 1
2009+
| document.anchors | Returns all elements that have a name attribute | 1 |
20102010
| document.applets | Deprecated | 1 |
20112011
| document.baseURI | Returns the absolute base URI of the document | 3 |
20122012
| document.body | Returns the element | 1 |
@@ -3034,32 +3034,57 @@ function showPosition(position) {
30343034
30353035
## AJAX
30363036
3037-
**XMLHttp** -
3037+
AJAX (Asynchronous JavaScript and XML) is a technique used in web development to create asynchronous web applications. It allows you to update parts of a web page without reloading the entire page. Originally, XML (eXtensible Markup Language) was commonly used for data exchange, but modern AJAX implementations often use JSON (JavaScript Object Notation) for data interchange due to its lighter syntax.
30383038
3039-
```javascript
3039+
**XMLHttp** - The XMLHttpRequest object is used to interact with servers asynchronously. Here's an example of creating an XMLHttpRequest object
30403040
3041+
```javascript
3042+
let xhttp = new XMLHttpRequest();
30413043
```
30423044
3043-
**Request** -
3045+
**Request** - To make a request to a server, you'll typically use methods like open() and send()
30443046
30453047
```javascript
3046-
3048+
xhttp.open('GET', 'https://api.example.com/data', true); // Method, URL, async (true or false)
3049+
xhttp.send(); // Send the request
30473050
```
30483051
3049-
**Response** -
3052+
You can also send data along with the request by passing parameters within the send() method.
30503053
3051-
```javascript
3054+
**Response** - Handling the response from the server can be done using event listeners like onreadystatechange and checking for the readyState and status of the request
30523055
3056+
```javascript
3057+
xhttp.onreadystatechange = function() {
3058+
if (this.readyState === 4 && this.status === 200) {
3059+
// Handle successful response
3060+
console.log(this.responseText); // Response data
3061+
} else {
3062+
// Handle errors
3063+
console.error('There was a problem with the request.');
3064+
}
3065+
};
30533066
```
30543067
3055-
**XML File** -
3068+
**XML File** - If you are working with an XML file, you can parse the response using methods like responseXML to access the XML data
30563069
30573070
```javascript
3058-
3071+
xhttp.onreadystatechange = function() {
3072+
if (this.readyState === 4 && this.status === 200) {
3073+
let xmlDoc = this.responseXML;
3074+
// Process xmlDoc for XML data
3075+
console.log(xmlDoc);
3076+
}
3077+
};
30593078
```
30603079
30613080
## JSON
30623081
3082+
JSON stands for JavaScript Object Notation
3083+
3084+
JSON is a text format for storing and transporting data
3085+
3086+
JSON is "self-describing" and easy to understand
3087+
30633088
### JSON Methods
30643089
30653090
parse() - Parses a JSON string and returns a JavaScript object
@@ -3079,34 +3104,39 @@ Data Types
30793104

30803105
```
30813106
3082-
**Parse** -
3083-
3084-
```javascript
3085-
3086-
```
3087-
3088-
**Stringify** -
3107+
**Parse** - The parse() method is used to parse a JSON string and convert it into a JavaScript object.
30893108
30903109
```javascript
3091-
3110+
const jsonString = '{"name": "John", "age": 30}';
3111+
const jsonObject = JSON.parse(jsonString);
3112+
console.log(jsonObject); // Output: { name: 'John', age: 30 }
30923113
```
30933114
3094-
**Objects** -
3115+
**Stringify** - The stringify() method is used to convert a JavaScript object into a JSON string.
30953116
30963117
```javascript
3097-
3118+
const jsonObject = { name: 'John', age: 30 };
3119+
const jsonString = JSON.stringify(jsonObject);
3120+
console.log(jsonString); // Output: '{"name":"John","age":30}'
30983121
```
30993122
3100-
**Arrays** -
3123+
**Objects** - Objects in JSON are key-value pairs enclosed in curly braces {}.
31013124
31023125
```javascript
3103-
3126+
const person = {
3127+
"name": "Alice",
3128+
"age": 30,
3129+
"address": {
3130+
"city": "New York",
3131+
"zipcode": "10001"
3132+
}
3133+
};
31043134
```
31053135
3106-
**Server** -
3136+
**Arrays** - Arrays in JSON are ordered lists of values enclosed in square brackets [].
31073137
31083138
```javascript
3109-
3139+
const colors = ["Red", "Green", "Blue"];
31103140
```
31113141
31123142
## JQuery
@@ -3884,15 +3914,206 @@ newObj();
38843914
38853915
## Snippets
38863916
3887-
```jsx
3917+
Here are a few JavaScript snippets that you might find useful:
38883918
3889-
```
3919+
1. **Hello World:**
38903920
3891-
## Short Hands
3921+
```javascript
3922+
console.log("Hello, World!");
3923+
```
38923924
3893-
```jsx
3925+
2. **Variable Declaration:**
38943926
3895-
```
3927+
```javascript
3928+
let variableName = "Some value";
3929+
```
3930+
3931+
3. **Conditional Statement (if-else):**
3932+
3933+
```javascript
3934+
let condition = true;
3935+
3936+
if (condition) {
3937+
console.log("Condition is true");
3938+
} else {
3939+
console.log("Condition is false");
3940+
}
3941+
```
3942+
3943+
4. **Loop (for):**
3944+
3945+
```javascript
3946+
for (let i = 0; i < 5; i++) {
3947+
console.log(i);
3948+
}
3949+
```
3950+
3951+
5. **Function Declaration:**
3952+
3953+
```javascript
3954+
function greet(name) {
3955+
console.log("Hello, " + name + "!");
3956+
}
3957+
3958+
greet("John");
3959+
```
3960+
3961+
6. **Array Manipulation:**
3962+
3963+
```javascript
3964+
let fruits = ['Apple', 'Banana', 'Orange'];
3965+
3966+
// Add an element to the end
3967+
fruits.push('Mango');
3968+
3969+
// Remove the last element
3970+
fruits.pop();
3971+
3972+
// Access elements by index
3973+
console.log(fruits[1]);
3974+
```
3975+
3976+
7. **Object Declaration:**
3977+
3978+
```javascript
3979+
let person = {
3980+
name: 'John',
3981+
age: 25,
3982+
profession: 'Developer'
3983+
};
3984+
3985+
// Accessing object properties
3986+
console.log(person.name);
3987+
```
3988+
3989+
8. **Async/Await:**
3990+
3991+
```javascript
3992+
async function fetchData() {
3993+
try {
3994+
let response = await fetch('https://api.example.com/data');
3995+
let data = await response.json();
3996+
console.log(data);
3997+
} catch (error) {
3998+
console.error('Error fetching data:', error);
3999+
}
4000+
}
4001+
4002+
fetchData();
4003+
```
4004+
4005+
9. **Event Handling:**
4006+
4007+
```javascript
4008+
let button = document.getElementById('myButton');
4009+
4010+
button.addEventListener('click', function() {
4011+
console.log('Button clicked!');
4012+
});
4013+
```
4014+
4015+
10. **LocalStorage:**
4016+
4017+
```javascript
4018+
// Save data to local storage
4019+
localStorage.setItem('username', 'JohnDoe');
4020+
4021+
// Retrieve data from local storage
4022+
let storedUsername = localStorage.getItem('username');
4023+
console.log('Username:', storedUsername);
4024+
```
4025+
4026+
## Short Hands
4027+
4028+
JavaScript offers several shorthand techniques to write code more concisely and improve readability. Here are some common JavaScript shorthand techniques:
4029+
4030+
1. **Ternary Operator:**
4031+
Instead of using an `if-else` statement, you can use the ternary operator for concise conditional expressions.
4032+
4033+
```javascript
4034+
// Long form
4035+
let result;
4036+
if (condition) {
4037+
result = 'true';
4038+
} else {
4039+
result = 'false';
4040+
}
4041+
4042+
// Shorthand
4043+
let result = condition ? 'true' : 'false';
4044+
```
4045+
4046+
2. **Nullish Coalescing Operator (`??`):**
4047+
This operator provides a concise way to provide a default value if a variable is null or undefined.
4048+
4049+
```javascript
4050+
// Long form
4051+
let value;
4052+
if (value !== null && value !== undefined) {
4053+
result = value;
4054+
} else {
4055+
result = 'default';
4056+
}
4057+
4058+
// Shorthand
4059+
let result = value ?? 'default';
4060+
```
4061+
4062+
3. **Arrow Functions:**
4063+
Arrow functions provide a concise syntax for writing function expressions.
4064+
4065+
```javascript
4066+
// Long form
4067+
function add(x, y) {
4068+
return x + y;
4069+
}
4070+
4071+
// Shorthand
4072+
const add = (x, y) => x + y;
4073+
```
4074+
4075+
4. **Template Literals:**
4076+
Template literals make it easier to concatenate strings and include variables within strings.
4077+
4078+
```javascript
4079+
// Long form
4080+
const greeting = 'Hello, ' + name + '!';
4081+
4082+
// Shorthand
4083+
const greeting = `Hello, ${name}!`;
4084+
```
4085+
4086+
5. **Object Property Shorthand:**
4087+
When creating an object with properties that have the same name as the variables being assigned, you can use shorthand notation.
4088+
4089+
```javascript
4090+
// Long form
4091+
const name = 'John';
4092+
const age = 30;
4093+
const user = {
4094+
name: name,
4095+
age: age
4096+
};
4097+
4098+
// Shorthand
4099+
const user = {
4100+
name,
4101+
age
4102+
};
4103+
```
4104+
4105+
6. **Destructuring Assignment:**
4106+
Destructuring allows you to extract values from arrays or objects and assign them to variables in a concise way.
4107+
4108+
```javascript
4109+
// Long form
4110+
const person = { name: 'John', age: 30 };
4111+
const name = person.name;
4112+
const age = person.age;
4113+
4114+
// Shorthand
4115+
const { name, age } = { name: 'John', age: 30 };
4116+
```
38964117
38974118
## List of GitHub Repositories to learn JavaScript
38984119

0 commit comments

Comments
 (0)