You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Node_JavaScript_Programming/javascript-programming.md
+56-2Lines changed: 56 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -355,9 +355,10 @@ To remove elements from an array in JavaScript, you can use the pop(), shift(),
355
355
Using filter(): It creates a new array with elements that pass the test implemented by the provided function.
356
356
357
357
Looping Through an Array in JavaScript
358
+
358
359
You can loop through an array in JavaScript using various methods such as for loop, forEach(), for...of loop, and map() method. Here's a brief overview of each method:
359
360
360
-
Using for loop:
361
+
Using `for` loop:
361
362
362
363
```js
363
364
for (let i = 0; i < array.length; i++) {
@@ -568,4 +569,57 @@ You can also remove duplicates from an array of objects in JavaScript using the
This code uses the filter() method in combination with the findIndex() method to create a new array containing only the first occurrence of each unique object. The Set object and the filter() method provide effective ways to remove duplicates from an array of objects in JavaScript, each with its own advantages and considerations
572
+
This code uses the filter() method in combination with the findIndex() method to create a new array containing only the first occurrence of each unique object. The Set object and the filter() method provide effective ways to remove duplicates from an array of objects in JavaScript, each with its own advantages and considerations
573
+
574
+
## Using Async and Await
575
+
576
+
To use async and await in JavaScript, you can follow these steps:
577
+
578
+
Declare an Async Function: Use the async keyword before a function to declare it as an async function. This means the function always returns a promise. For example:
579
+
580
+
async function myFunction() {
581
+
return "Hello";
582
+
}
583
+
584
+
Use the Await Keyword: Inside an async function, you can use the await keyword before a call to a function that returns a promise. This makes the code wait until the promise is resolved before continuing. For example:
585
+
586
+
let result = await myPromise;
587
+
588
+
Error Handling: You can use try...catch blocks to handle errors when using async and await.
589
+
590
+
To handle errors when using async and await in JavaScript, you can use the try...catch block. Here's how you can do it:
591
+
592
+
async function myFunction() {
593
+
try {
594
+
let result = await someAsyncTask();
595
+
// Code to handle the result
596
+
} catch (error) {
597
+
// Code to handle the error
598
+
}
599
+
}
600
+
601
+
This allows you to catch and handle any errors that occur during the execution of the await-ed promise. As for the second part of your question, yes, async and await can be used with promises in JavaScript. The await keyword is used to wait for a promise to resolve, and it can only be used inside an async function. When used together, they provide a more readable and maintainable way to work with promises.
602
+
603
+
## Other different types of JavaScript files
604
+
605
+
-`.cjs` file extension
606
+
607
+
This is for CommonJS. CommonJS is a project that aims to standardize the module ecosystem for JavaScript outside of web browsers, such as on web servers or native desktop applications. It provides a specification for how modules should work and is widely used for server-side JavaScript with Node.js. CommonJS can be recognized by the use of the require() function and module.exports, while ES modules use import and export statements for similar functionality. The .cjs file extension is associated with CommonJS code, which is intended to allow JavaScript to be used in environments beyond a frontend web browser. It also allows JavaScript to be used in environments beyond a frontend web browser
608
+
CommonJS is a module system for JavaScript used in server-side environments like Node.js.
609
+
610
+
- ``.mjs` file extension
611
+
612
+
The .mjs file extension is used to indicate that a JavaScript file uses the ECMAScript module format, providing a standardized way to organize and share JavaScript code across multiple files and projects. ES6 modules, which are denoted by the .mjs extension, offer several advantages over traditional .js files, including native support for ES6 modules, a clear distinction between modules and regular scripts, and improved compatibility with bundlers and build tools
613
+
614
+
The .mjs file extension is commonly used in Node.js for ECMAScript modules, providing a standardized way to organize and share JavaScript code across multiple files and projects. Some common use cases for .mjs files in Node.js include:
615
+
616
+
Native Support for ES6 Modules: The .mjs file extension leverages the native support for ES6 modules in modern JavaScript runtimes, allowing the use of the import and export keywords to define and use modules without the need for additional tools or transpilation
617
+
618
+
Clear Distinction Between Modules and Scripts: The use of .mjs file extension helps differentiate between modules and regular scripts, enabling developers to quickly identify and work with modules in their projects
619
+
620
+
Improved Compatibility with Bundlers and Build Tools: As the new module system gains popularity, bundlers and build tools have started to adopt native ES6 module support. Using the .mjs file extension ensures better compatibility with these tools, allowing for seamless integration into existing development workflows
621
+
622
+
-`.ejs` file extension
623
+
624
+
EJS, or Embedded JavaScript, is a simple templating language that allows the generation of HTML markup with plain JavaScript. It is commonly used as a template engine in Node.js to create HTML templates with minimal code and to inject data into an HTML template on the client side, producing the final HTML. EJS enables the embedding of JavaScript into HTML pages, and it is often used with Express, a web application framework for Node.js. EJS files typically use the .ejs file extension. To use EJS in a Node.js project, the EJS package can be installed via npm, and the templating engine can be set up with Express. EJS is known for its ease of use, as it allows the direct use of JavaScript to generate the desired HTML output. It also provides features such as partials and the ability to pass variables to views, making it a powerful tool for building web applications
This is a collection of Markdown notes written in Obsidian for programming and it includes notes on C, C++, using and configuring VSCode and many other things programming related. Anyone is welcome to contribute to this Markdown repository and make corrections.
3
+
This is a collection of Markdown notes written in Obsidian for programming, coding, software engineering, software development and it includes notes on C, C++, using and configuring VSCode and many other things programming related. Anyone is welcome to contribute to this Markdown repository and make corrections.
4
+
5
+
Keep in mind these notes are Open Source. If I get it wrong, correct it in a PR or a issue or open a discussion.
6
+
7
+
Also, keep in mind these things are written just as I understand them, so they might be wrong. They have been copied from either hand written or typed notes I have written to help me in case I forgot how to do something in programming. If you use these things, Please verify that they work.
8
+
9
+
You don't have to use Obsidian to read this collection of notes, but it might help.
Copy file name to clipboardExpand all lines: React_Development/react-development-notes.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,3 +39,5 @@ Other components:
39
39
These components can be combined in different ways to form various tech stacks, such as the MEAN stack (MongoDB, Express, Angular, Node.js) or the LAMP stack (Linux, Apache, MySQL, PHP)
40
40
41
41
The choice of tech stack depends on the specific requirements of the project and the skills of the development team.
42
+
43
+
In the latest versions of React, and you are using JavaScript with React instead of TypeScript, you should be focused on using at least ES6 or ES2015 so that you have access to `import` and `export`
Copy file name to clipboardExpand all lines: about-manifest-json.md
+42-39Lines changed: 42 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,43 +34,43 @@ At a minimum, a manifest file should contain the following manifest members: "na
34
34
An example manifest.json,
35
35
36
36
```json
37
-
{
38
-
"name": "My Web App",
39
-
"displayName": "My Web App",
40
-
"background_color": "#ffffff",
41
-
"dir": "ltr",
42
-
"display": "standalone",
43
-
"icons": [
44
-
{
45
-
"src": "icon-192.png",
46
-
"sizes": "192x192",
47
-
"type": "image/png"
48
-
},
49
-
{
50
-
"src": "icon-512.png",
51
-
"sizes": "512x512",
52
-
"type": "image/png"
53
-
}
54
-
],
55
-
"lang": "en-US",
56
-
"orientation": "portrait",
57
-
"start_url": "/",
58
-
"id": "com.example.mywebapp",
59
-
"scope": "/",
60
-
"manifest_version": 2,
61
-
"type": "web_app",
62
-
"meta": {
63
-
"author": "John Doe",
64
-
"description": "A simple web app",
65
-
"version": "1.0.0"
66
-
},
67
-
"dependencies": {
68
-
"react": "^17.0.2",
69
-
"react-dom": "^17.0.2"
70
-
},
71
-
"defaultWidth": 800,
72
-
"defaultHeight": 600,
73
-
"resizeX": true
37
+
{
38
+
"name": "My Web App",
39
+
"displayName": "My Web App",
40
+
"background_color": "#ffffff",
41
+
"dir": "ltr",
42
+
"display": "standalone",
43
+
"icons": [
44
+
{
45
+
"src": "icon-192.png",
46
+
"sizes": "192x192",
47
+
"type": "image/png"
48
+
},
49
+
{
50
+
"src": "icon-512.png",
51
+
"sizes": "512x512",
52
+
"type": "image/png"
53
+
}
54
+
],
55
+
"lang": "en-US",
56
+
"orientation": "portrait",
57
+
"start_url": "/",
58
+
"id": "com.example.mywebapp",
59
+
"scope": "/",
60
+
"manifest_version": 2,
61
+
"type": "web_app",
62
+
"meta": {
63
+
"author": "John Doe",
64
+
"description": "A simple web app",
65
+
"version": "1.0.0"
66
+
},
67
+
"dependencies": {
68
+
"react": "^17.0.2",
69
+
"react-dom": "^17.0.2"
70
+
},
71
+
"defaultWidth": 800,
72
+
"defaultHeight": 600,
73
+
"resizeX": true
74
74
}
75
75
```
76
76
@@ -86,6 +86,9 @@ The file typically includes information such as the application or extension nam
86
86
87
87
The manifest.json file affects web app performance by providing important metadata and configuration settings that help browsers and platforms understand and interact with the application, and by enabling the app to behave like a native app when installed on the user's device, which can improve user engagement and performance
88
88
89
-
Having a manifest.json file available to browsers on your website or web page, even if it's not an app or a Progressive Web App (PWA), can have an impact on SEO and performance. Search engines consider PWAs and websites with manifest.json files more favorably, which can lead to improved SEO. Additionally, using a manifest.json file can enhance user experience by allowing the website to be installed as a PWA, providing an immersive and engaging experience for users. It can also lead to increased user engagement and improved performance, as PWAs can cache website data and work offline, reducing the need to download data from the server repeatedly
89
+
Having a `manifest.json` file available to browsers on your website or web page, even if it's not an app or a Progressive Web App (PWA), can have an impact on SEO and performance. Search engines consider PWAs and websites with `manifest.json` files more favorably, which can lead to improved SEO. Additionally, using a `manifest.json` file can enhance user experience by allowing the website to be installed as a PWA, providing an immersive and engaging experience for users. It can also lead to increased user engagement and improved performance, as PWAs can cache website data and work offline, reducing the need to download data from the server repeatedly
90
90
91
-
Therefore, while not strictly required for a traditional website, having a manifest.json file can still have positive effects on SEO and user experience
91
+
Therefore, while not strictly required for a traditional website, having a manifest.json file can still have positive effects on SEO and user experience.
92
+
93
+
In Firefox, once the browser loads the page, if it locates a `manifest.json` file, you can open the browser console and click on the `Application`
94
+
tab and click on Manifest. This section will display the properties you have set in the `manifest.json` file.
Copy file name to clipboardExpand all lines: configure-eslint.md
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,12 +29,15 @@ Besides the .eslintrc file, ESLint also recognizes the following files as config
29
29
- .eslintrc.yaml or .eslintrc.yml: These are YAML files to define the configuration structure.
30
30
31
31
- .eslintrc.json: This is a JSON file to define the configuration structure. ESLint’s JSON files also allow JavaScript-style comments.
32
-
package.json: You can create an eslintConfig property in your package.json file and define your configuration there. If there are multiple configuration files in the same directory, ESLint only uses one.
32
+
33
+
- package.json: You can create an eslintConfig property in your package.json file and define your configuration there. If there are multiple configuration files in the same directory, ESLint only uses one.
33
34
34
35
The priority order is as follows: .eslintrc.js, .eslintrc.cjs, .eslintrc.yaml, .eslintrc.yml, .eslintrc.json, package.json
35
36
36
37
These files provide flexibility in how you can define and manage your ESLint configurations.
37
38
39
+
As you gain familiarity with ESLint, You should build a baseline configuration and store the rather than just rely on the defaults so that you can get to work easily on your project and store it somewhere handy so that you can copy and paste it into your project. If you work on various types of JavaScript projects and frameworks, you might even have several configurations you can rely on.
40
+
38
41
## Installing ESLint
39
42
40
43
Install the ESLint package in your project using npm:
@@ -66,4 +69,4 @@ There are plugins for ESLint. An ESLint plugin is an npm module that can contain
66
69
67
70
Each plugin is an npm module with a name in the format of eslint-plugin-<plugin-name>, such as eslint-plugin-react. Plugins can also provide additional environments, custom processors, and configurations
68
71
69
-
You should be able to easily find a list of awesome ESLint plugins, configs, etc. on GitHub
72
+
You should be able to easily find a list of awesome ESLint plugins, configs, etc. on GitHub
Prettier is an opinionated code formatter that supports various languages. It enforces a consistent code style by parsing the code and reprinting it from scratch, taking the line length into account. It supports languages such as JavaScript (including experimental features), JSX, Angular, Vue, Flow, TypeScript, CSS, Less, SCSS, HTML, Ember/Handlebars, JSON, GraphQL, Markdown (including GFM and MDX v1), and Y
3
+
Prettier is an opinionated code formatter that supports various languages. It enforces a consistent code style by parsing the code and reprinting it from scratch, taking the line length into account. It supports languages such as JavaScript (including experimental features), JSX, Angular, Vue, Flow, TypeScript, CSS, Less, SCSS, HTML, Ember/Handlebars, JSON, GraphQL, Markdown (including GFM and MDX v1).
4
4
5
-
To configure Prettier, you can use a "prettier" key in your package.json file, a .prettierrc file written in JSON or YAML, a .prettierrc, .prettierrc.js or prettier.config.js file, or a .prettierrc.toml file, among other options.
5
+
To configure Prettier, you can use a "prettier" key in your package.json file, a .prettierrc file written in JSON or YAML, prettierrc.js or prettier.config.js file, or a .prettierrc.toml file, among other options. According to recent Prettier documentation online, the current way to configure prettier is using a prettier.config.js file, but the other formats are still supported.
6
6
7
7
Prettier intentionally doesn’t support any kind of global configuration to ensure consistent behavior across different environments
8
8
9
9
Prettier also supports the use of plugins to add new languages or formatting rules. Official plugins include @prettier/plugin-php, @prettier/plugin-pug, @prettier/plugin-ruby, and many more. Community plugins are also available for a wide range of languages
10
+
11
+
If you're following along doing some Web Development, you will find this tool to help you format HTML, CSS, JavaScript.
12
+
13
+
## Extensions, Plugins
14
+
15
+
There are some ESLint plugins and extensions for VSCode.
0 commit comments