<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sanket De</title>
    <description>The latest articles on DEV Community by Sanket De (@sanketcode67).</description>
    <link>https://dev.to/sanketcode67</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1079777%2F9dfc0392-8fa7-40b6-8797-96a434fdae67.jpeg</url>
      <title>DEV Community: Sanket De</title>
      <link>https://dev.to/sanketcode67</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sanketcode67"/>
    <language>en</language>
    <item>
      <title>Django Framework</title>
      <dc:creator>Sanket De</dc:creator>
      <pubDate>Thu, 15 Jun 2023 12:46:25 +0000</pubDate>
      <link>https://dev.to/sanketcode67/django-framework-features-2ine</link>
      <guid>https://dev.to/sanketcode67/django-framework-features-2ine</guid>
      <description>&lt;h3&gt;
  
  
  MVT Architecture
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Django&lt;/strong&gt;, a Python framework to create web applications, is based on Model-View-Template (MVT) architecture.  &lt;strong&gt;MVT&lt;/strong&gt;  is a software design pattern for developing a web application. It consists of the following three entities:

&lt;ol&gt;
&lt;li&gt; Model&lt;/li&gt;
&lt;li&gt; View&lt;/li&gt;
&lt;li&gt; Template&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Model&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A  &lt;strong&gt;Model&lt;/strong&gt;  is an object that defines the structure of the data in the Django application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is responsible for maintaining the entire application’s data for which it provides various mechanisms to add, update, read and delete the data in the database.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;View&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A  &lt;strong&gt;View&lt;/strong&gt;  is a handler function that accepts HTTP requests, processes them, and returns the HTTP response.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It retrieves the necessary data to fulfill the request using Models and renders them on the user interface using Templates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It can also create an HTML page using an HTML template dynamically, and populate it with data fetched from the model.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Template&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A  template  is a text file that defines the structure or layout of the user interface. The text file can be any type of file; for example HTML, XML, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Settings file
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Secret Key&lt;/strong&gt;
A secret key used for cryptographic signing and securing sessions, forms, and other sensitive data. It should be kept secret and unique for each project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Debug Mode&lt;/strong&gt;
A boolean flag indicating whether the project is in debug mode or not. In debug mode. It's recommended to set &lt;code&gt;DEBUG = False&lt;/code&gt; in production for security reasons.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Allowed Host&lt;/strong&gt;
A list of strings representing the host/domain names that the project can serve. It is a security measure to prevent HTTP Host header attacks. In production, you should specify the actual domain names or IP addresses that your project will be served from.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database Configuration&lt;/strong&gt;
DATABASES: A dictionary containing the configuration settings for the project's database connections.You can specify the database engine, name, user credentials, host, and other database-specific settings.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Application configuration&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  INSTALLED_APPS: A list of Django applications installed in the project.&lt;/li&gt;
&lt;li&gt;  Each application can define models, views, templates, and other components.&lt;/li&gt;
&lt;li&gt;  Third-party applications are typically included by specifying their package            names.&lt;/li&gt;
&lt;li&gt;  Your project's custom applications should also be included here.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In Django inside INSTALLED_APPS there are several default applicaition&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;django.contrib.admin&lt;/code&gt;: This app provides the Django admin interface, which allows you to manage and interact with your project's data models through a web-based interface.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;django.contrib.auth&lt;/code&gt;: This app provides authentication and authorization functionality, including user authentication, permissions, and user management.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;django.contrib.contenttypes&lt;/code&gt;: This app provides a framework for creating, storing, and retrieving content types. It is used by other apps to implement generic relationships between models.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;django.contrib.sessions&lt;/code&gt;: This app manages user sessions and provides session-based data storage.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;django.contrib.messages&lt;/code&gt;: This app enables cookie- and session-based messaging between users and provides support for displaying success messages, error messages, etc.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;django.contrib.staticfiles&lt;/code&gt;: This app helps manage static files (CSS, JavaScript, images etc) and serves them during development.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Middleware&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Middleware in Django is a component that sits between the web server and the view, providing a way to process requests and responses globally before they reach the view or after they leave the view. &lt;/li&gt;
&lt;li&gt;It allows you to add functionality to the request/response processing pipeline.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Django Security&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Django is a well-known and widely used web framework that emphasizes security. &lt;/li&gt;
&lt;li&gt;It provides a range of built-in security features and follows best practices to help developers build secure web applications.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Cross-Site Scripting (XSS) Protection&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Django automatically escapes data rendered in templates, which helps prevent XSS attacks by default.&lt;/li&gt;
&lt;li&gt;  Developers can also use the built-in template tags and filters, such as &lt;code&gt;|safe&lt;/code&gt;, to mark specific content as safe from escaping.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Cross-Site Request Forgery (CSRF) Protection&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Django provides CSRF protection by generating and validating CSRF tokens for all POST forms.&lt;/li&gt;
&lt;li&gt;  The CSRF token is included in form submissions and verified on the server side to ensure that the request is legitimate.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;User Authentication and Authorization&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Django includes a robust authentication system that handles user registration, login, password hashing, and session management.&lt;/li&gt;
&lt;li&gt;  It supports various authentication backends, including username/password, email/password, social authentication, and more.&lt;/li&gt;
&lt;li&gt;  Django provides an authorization framework, including user roles, permissions, and groups, to control access to resources.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Password Hashing&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Django uses strong cryptographic algorithms, such as PBKDF2, bcrypt, or Argon2, for password hashing.&lt;/li&gt;
&lt;li&gt;  It automatically handles password salting and stretching to protect against brute-force attacks.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Clickjacking Protection&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; This type of attack occurs when a malicious site tricks a user into clicking on a concealed element of another site which they have loaded in a hidden frame or iframe.&lt;/li&gt;
&lt;li&gt;  Django includes the &lt;code&gt;XFrameOptionsMiddleware&lt;/code&gt; middleware, which sets the &lt;code&gt;X-Frame-Options&lt;/code&gt; header to prevent clickjacking attacks.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;WSGI&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;WSGI stands for Web Server Gateway Interface. It is a specification that defines how web servers and web applications written in Python should communicate with each other. &lt;/li&gt;
&lt;li&gt;WSGI acts as a bridge between web servers (such as Apache or Nginx) and web applications (such as Django).&lt;/li&gt;
&lt;li&gt;In the Django, WSGI is used to connect the Django web framework with a web server. &lt;/li&gt;
&lt;li&gt;It allows the web server to forward requests to Django and receive responses back. This enables Django to run as a standalone web application, handling HTTP requests and generating HTTP responses.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Models file
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In Django's &lt;code&gt;models.py&lt;/code&gt; file, you define the structure and behavior of your application's data using classes that inherit from Django's &lt;code&gt;Model&lt;/code&gt; class. &lt;/li&gt;
&lt;li&gt;These classes represent database tables, and the attributes of the classes define the fields and relationships of the corresponding database table columns.&lt;/li&gt;
&lt;li&gt; In Django, &lt;code&gt;on_delete=Cascade&lt;/code&gt; is a parameter used when defining a foreign key relationship between two models. It specifies what should happen when the referenced object (the object being referred to by the foreign key) is deleted.&lt;/li&gt;
&lt;li&gt;When &lt;code&gt;on_delete=Cascade&lt;/code&gt; is specified, it means that if the referenced object is deleted, the objects that have a foreign key pointing to it will also be deleted (cascaded).&lt;/li&gt;
&lt;li&gt;Fields and Validators: In Django's models, we have a variety of fields and validators available to define the characteristics and constraints of your model's attributes.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Some commonly used fields include &lt;code&gt;CharField&lt;/code&gt; (for storing character strings), &lt;code&gt;IntegerField&lt;/code&gt; (for storing integers), &lt;code&gt;DateField&lt;/code&gt; (for storing dates), and &lt;code&gt;ForeignKey&lt;/code&gt; (for establishing relationships with other models).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validators, on the other hand, are functions or classes that validate the values of model fields based on certain criteria. Django provides built-in validators such as &lt;code&gt;MaxValueValidator&lt;/code&gt;, &lt;code&gt;MinValueValidator&lt;/code&gt;, &lt;code&gt;EmailValidator&lt;/code&gt;, and &lt;code&gt;RegexValidator&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can also create custom validators to enforce specific validation rules on your model's fields.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Django ORM
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Django ORM (Object-Relational Mapping) is a powerful feature of Django that allows you to interact with your database using Python code instead of writing raw SQL queries.&lt;/li&gt;
&lt;li&gt;In the Django shell, you can execute ORM queries to interactively work with your Django models and perform database operations.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;run the folloing command to get into django shell&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python manage.py shell
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.educative.io/answers/what-is-mvt-structure-in-django"&gt;https://www.educative.io/answers/what-is-mvt-structure-in-django&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.djangoproject.com/en/4.2/topics/http/middleware/"&gt;https://docs.djangoproject.com/en/4.2/topics/http/middleware/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://medium.com/scalereal/everything-you-need-to-know-about-middleware-in-django-2a3bd3853cd6"&gt;https://medium.com/scalereal/everything-you-need-to-know-about-middleware-in-django-2a3bd3853cd6&lt;/a&gt;&lt;br&gt;
&lt;a href="https://frontegg.com/blog/django-authentication"&gt;https://frontegg.com/blog/django-authentication&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Asynchronous JavaScript</title>
      <dc:creator>Sanket De</dc:creator>
      <pubDate>Thu, 01 Jun 2023 09:45:49 +0000</pubDate>
      <link>https://dev.to/sanketcode67/asynchronous-javascript-297d</link>
      <guid>https://dev.to/sanketcode67/asynchronous-javascript-297d</guid>
      <description>&lt;h2&gt;
  
  
  Callbacks
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In JavaScript, a callback is a function that is passed as an argument to another function and is executed later, typically after some asynchronous operation or when a certain condition is met. &lt;/li&gt;
&lt;li&gt;Callbacks are commonly used in JavaScript to handle asynchronous tasks like making API calls, handling events, and executing code after a certain operation completes.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sayGoodbye&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Goodbye!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sanket&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sayGoodbye&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In the above example, we have two functions: &lt;code&gt;greet&lt;/code&gt; and &lt;code&gt;sayGoodbye&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;The &lt;code&gt;greet&lt;/code&gt; function takes two arguments: &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;callback&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;It logs a greeting message with the provided name and then calls the &lt;code&gt;callback&lt;/code&gt; function. In this case, &lt;code&gt;sayGoodbye&lt;/code&gt; is passed as the callback function to &lt;code&gt;greet&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;When &lt;code&gt;greet&lt;/code&gt; is invoked with the name 'Sanket', it logs "Hello, Sanket!" and then calls the &lt;code&gt;sayGoodbye&lt;/code&gt; function, which logs "Goodbye!".&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Promises
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In JavaScript, promises are used to handle asynchronous operations in a more structured way compared to callbacks. &lt;/li&gt;
&lt;li&gt;A promise represents the eventual completion (or failure) of an asynchronous operation and allows you to attach callbacks to handle the resolved value or the error.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;No name provided!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sanket&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In the above example, the &lt;code&gt;greet&lt;/code&gt; function returns a new Promise. &lt;/li&gt;
&lt;li&gt;Inside the promise, we created an asynchronous operation using &lt;code&gt;setTimeout&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;If a name is provided, the promise is resolved with the greeting message. Otherwise, it is rejected with an error message.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code Control
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In JavaScript, when an asynchronous operation, such as making an API call or waiting for a timer, is encountered, it is typically handled by the JavaScript runtime environment rather than directly controlled through code. &lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Here's a high-level overview of how the flow of data occurs in asynchronous operations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Synchronous Execution:&lt;/strong&gt; JavaScript code is executed synchronously, line by line, in a single thread. Functions are pushed onto the call stack, and when a function call is encountered, it is executed and then removed from the stack.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Asynchronous Operations:&lt;/strong&gt; When an asynchronous operation, such as an API call, is encountered, it is offloaded to the browser's web API. The web API handles the operation asynchronously and continues executing the rest of the code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Callback/Event Handler:&lt;/strong&gt; In asynchronous operations, callbacks or event handlers are typically registered to handle the completion or response of the operation. These callbacks are not executed immediately but are scheduled to be placed in the task queue once the operation is complete.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Task Queue:&lt;/strong&gt; The task queue (also known as the event queue) holds the callbacks or event handlers that are ready to be executed. Once the call stack is empty, JavaScript checks the task queue for any pending tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event Loop:&lt;/strong&gt; The event loop constantly checks if the call stack is empty. If the stack is empty, it takes the first task from the task queue and pushes it onto the call stack for execution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Execution of Callbacks:&lt;/strong&gt; The callbacks or event handlers are executed one by one in the order they were added to the task queue. These callbacks can contain code that manipulates data, updates the user interface, or triggers further asynchronous operations.&lt;/li&gt;
&lt;li&gt;This flow allows JavaScript to handle asynchronous operations without blocking the main thread and ensures that callbacks are executed in the correct order.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/js/js_async.asp"&gt;https://www.w3schools.com/js/js_async.asp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.programiz.com/javascript/async-await"&gt;https://www.programiz.com/javascript/async-await&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.freecodecamp.org/news/asynchronous-javascript/"&gt;https://www.freecodecamp.org/news/asynchronous-javascript/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
  </channel>
</rss>
