<?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: Atchukola Naresh</title>
    <description>The latest articles on DEV Community by Atchukola Naresh (@god7780).</description>
    <link>https://dev.to/god7780</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1081461%2Ff30434d7-c6c6-448c-9b8a-ecc7148fe13b.png</url>
      <title>DEV Community: Atchukola Naresh</title>
      <link>https://dev.to/god7780</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/god7780"/>
    <language>en</language>
    <item>
      <title>Django Technical Paper</title>
      <dc:creator>Atchukola Naresh</dc:creator>
      <pubDate>Thu, 15 Jun 2023 13:07:13 +0000</pubDate>
      <link>https://dev.to/god7780/django-technical-paper-4b12</link>
      <guid>https://dev.to/god7780/django-technical-paper-4b12</guid>
      <description>&lt;h3&gt;
  
  
  What is secret key?
&lt;/h3&gt;

&lt;p&gt;A Django secret key is a random string that is used to protect your Django application from security attacks. It is used for a variety of purposes, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Signing cookies: Cookies are small files that are stored on a user's computer when they visit your website. They can be used to store information about the user, such as their username, password, and session ID. Django uses a secret key to sign cookies, which helps to prevent them from being tampered with.&lt;/li&gt;
&lt;li&gt;-   Generating CSRF tokens: CSRF (Cross-Site Request Forgery) is a type of attack that allows an attacker to trick a user into performing an action on a website without their knowledge or consent. Django uses a secret key to generate CSRF tokens, which are used to protect against CSRF attacks.&lt;/li&gt;
&lt;li&gt;-   Generating password reset tokens: When a user forgets their password, they can request a password reset link to be sent to their email address. This link contains a password reset token, which is used to verify the user's identity and reset their password. Django uses a secret key to generate password reset tokens.&lt;/li&gt;
&lt;li&gt;It is important to keep your Django secret key secret. If it is compromised, an attacker could use it to perform a variety of security attacks on your application. You should never share your Django secret key with anyone, and you should never commit it to version control.&lt;/li&gt;
&lt;li&gt;To generate a Django secret key, you can use the following command:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python -c 'import random; print(random.SystemRandom().get_random_bytes(32))'

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

&lt;/div&gt;



&lt;p&gt;This will generate a 32-character random string. You can then copy and paste this string into your Django settings file.&lt;/p&gt;

&lt;p&gt;The Django secret key is a critical part of your Django application's security. By keeping it secret, you can help to protect your application from security attacks.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are the default Django apps inside it? Are there more?
&lt;/h3&gt;

&lt;p&gt;Django comes with a number of default apps that are installed when you create a new project. These apps provide basic functionality that is commonly needed in web applications, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Admin:&lt;/strong&gt;  A web-based interface for managing your Django project's content, users, and other settings.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Auth:&lt;/strong&gt;  A system for authenticating users and managing their permissions.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Contenttypes:&lt;/strong&gt;  A system for defining and managing the types of content that can be stored in your Django project.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Sessions:&lt;/strong&gt;  A system for tracking user sessions and storing session data.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Messages:&lt;/strong&gt;  A system for sending and receiving messages between users.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Staticfiles:&lt;/strong&gt;  A system for managing static files, such as images, CSS, and JavaScript.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition to the default apps, there are a number of third-party apps that can be installed and used with Django. These apps provide additional functionality, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Django Rest Framework:&lt;/strong&gt;  A powerful framework for building RESTful APIs.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Django Channels:&lt;/strong&gt;  A framework for building real-time applications.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Django Celery:&lt;/strong&gt;  A framework for running asynchronous tasks.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Django South:&lt;/strong&gt;  A migration tool for managing changes to your Django project's database schema.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Django Debug Toolbar:&lt;/strong&gt;  A powerful tool for debugging Django applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The number of default Django apps is subject to change, but there will always be a number of core apps that are included with Django. These apps provide the basic functionality that is needed to build a web application. Third-party apps can be used to add additional functionality to your Django project.&lt;/p&gt;

&lt;p&gt;If you are new to Django, I recommend that you start with the default apps. Once you have a basic understanding of how Django works, you can start exploring third-party apps.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is middleware in django? What are different kinds of middleware in django? Read up a little on each security issue?
&lt;/h3&gt;

&lt;p&gt;Middleware in Django is a way to add custom functionality to your Django application. It is a general-purpose framework that allows you to intercept and modify requests and responses before they reach your views. Middleware can be used for a variety of purposes, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Authentication and authorization&lt;/li&gt;
&lt;li&gt;  Session management&lt;/li&gt;
&lt;li&gt;  Caching&lt;/li&gt;
&lt;li&gt;  Security&lt;/li&gt;
&lt;li&gt;  Performance optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Django includes a number of built-in middleware, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  AuthenticationMiddleware: This middleware handles authentication for your application.&lt;/li&gt;
&lt;li&gt;  SessionMiddleware: This middleware handles session management for your application.&lt;/li&gt;
&lt;li&gt;  GzipMiddleware: This middleware compresses responses to reduce bandwidth usage.&lt;/li&gt;
&lt;li&gt;  CommonMiddleware: This middleware provides a number of common features, such as error handling and static file serving.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also write your own middleware. To do this, you need to create a class that inherits from the &lt;code&gt;MiddlewareMixin&lt;/code&gt; class. Your class must define the &lt;code&gt;process_request()&lt;/code&gt; and &lt;code&gt;process_response()&lt;/code&gt; methods. The &lt;code&gt;process_request()&lt;/code&gt; method is called before the request is passed to your views, and the &lt;code&gt;process_response()&lt;/code&gt; method is called after the response is generated by your views.&lt;/p&gt;

&lt;p&gt;Here are some of the security issues that can be addressed with middleware:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Cross-site request forgery (CSRF): CSRF is a type of attack where an attacker tricks a user into submitting a form to your application without their knowledge. This can be used to perform actions on behalf of the user, such as transferring money out of their account or making a purchase.&lt;/li&gt;
&lt;li&gt;  Cross-site scripting (XSS): XSS is a type of attack where an attacker injects malicious code into a web page that is viewed by a user. This malicious code can then be executed on the user's computer, potentially stealing their cookies or other sensitive information.&lt;/li&gt;
&lt;li&gt;  Session fixation: Session fixation is a type of attack where an attacker tricks a user into using a session ID that the attacker has chosen. This allows the attacker to take control of the user's session and perform actions on their behalf.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Middleware can be used to mitigate these security risks by checking requests for malicious content, enforcing authentication, and managing sessions securely.&lt;/p&gt;

&lt;p&gt;Here are some examples of how middleware can be used to improve security:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The  &lt;code&gt;CSRFMiddleware&lt;/code&gt;  class checks requests for the presence of a CSRF token. If the token is not present or is invalid, the request is rejected.&lt;/li&gt;
&lt;li&gt;  The  &lt;code&gt;XSSMiddleware&lt;/code&gt;  class scans responses for malicious code. If any malicious code is found, it is replaced with harmless text.&lt;/li&gt;
&lt;li&gt;  The  &lt;code&gt;SessionMiddleware&lt;/code&gt;  class ensures that sessions are created securely and that session IDs are not exposed to users.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By using middleware, you can add additional security features to your Django application and protect your users from a variety of attacks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cross site request forgery (CSRF)
&lt;/h2&gt;

&lt;p&gt;CSRF attacks allow a malicious user to execute actions using the credentials of another user without that user’s knowledge or consent.&lt;/p&gt;

&lt;p&gt;Django has built-in protection against most types of CSRF attacks, providing you have  &lt;a href="https://docs.djangoproject.com/en/4.0/ref/csrf/#using-csrf"&gt;enabled and used it&lt;/a&gt;  where appropriate. However, as with any mitigation technique, there are limitations. For example, it is possible to disable the CSRF module globally or for particular views. You should only do this if you know what you are doing. There are other  &lt;a href="https://docs.djangoproject.com/en/4.0/ref/csrf/#csrf-limitations"&gt;limitations&lt;/a&gt;  if your site has subdomains that are outside of your control.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.djangoproject.com/en/4.0/ref/csrf/#how-csrf-works"&gt;CSRF protection works&lt;/a&gt;  by checking for a secret in each POST request. This ensures that a malicious user cannot “replay” a form POST to your website and have another logged in user unwittingly submit that form. The malicious user would have to know the secret, which is user specific (using a cookie).&lt;/p&gt;

&lt;p&gt;When deployed with  &lt;a href="https://docs.djangoproject.com/en/4.0/topics/security/#security-recommendation-ssl"&gt;HTTPS&lt;/a&gt;,  &lt;code&gt;CsrfViewMiddleware&lt;/code&gt;  will check that the HTTP referer header is set to a URL on the same origin (including subdomain and port). Because HTTPS provides additional security, it is imperative to ensure connections use HTTPS where it is available by forwarding insecure connection requests and using HSTS for supported browsers.&lt;/p&gt;

&lt;p&gt;Be very careful with marking views with the  &lt;code&gt;csrf_exempt&lt;/code&gt;  decorator unless it is absolutely necessary.&lt;/p&gt;

&lt;h2&gt;
  
  
  SQL injection protection
&lt;/h2&gt;

&lt;p&gt;SQL injection is a type of attack where a malicious user is able to execute arbitrary SQL code on a database. This can result in records being deleted or data leakage.&lt;/p&gt;

&lt;p&gt;Django’s querysets are protected from SQL injection since their queries are constructed using query parameterization. A query’s SQL code is defined separately from the query’s parameters. Since parameters may be user-provided and therefore unsafe, they are escaped by the underlying database driver.&lt;/p&gt;

&lt;p&gt;Django also gives developers power to write  &lt;a href="https://docs.djangoproject.com/en/4.0/topics/db/sql/#executing-raw-queries"&gt;raw queries&lt;/a&gt;  or execute  &lt;a href="https://docs.djangoproject.com/en/4.0/topics/db/sql/#executing-custom-sql"&gt;custom sql&lt;/a&gt;. These capabilities should be used sparingly and you should always be careful to properly escape any parameters that the user can control. In addition, you should exercise caution when using  &lt;a href="https://docs.djangoproject.com/en/4.0/ref/models/querysets/#django.db.models.query.QuerySet.extra"&gt;&lt;code&gt;extra()&lt;/code&gt;&lt;/a&gt;  and  &lt;a href="https://docs.djangoproject.com/en/4.0/ref/models/expressions/#django.db.models.expressions.RawSQL"&gt;&lt;code&gt;RawSQL&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clickjacking protection:
&lt;/h2&gt;

&lt;p&gt;Clickjacking is a type of attack where a malicious site wraps another site in a frame. This attack can result in an unsuspecting user being tricked into performing unintended actions on the target site.&lt;/p&gt;

&lt;p&gt;Django contains  &lt;a href="https://docs.djangoproject.com/en/4.0/ref/clickjacking/#clickjacking-prevention"&gt;clickjacking protection&lt;/a&gt;  in the form of the  &lt;a href="https://docs.djangoproject.com/en/4.0/ref/middleware/#django.middleware.clickjacking.XFrameOptionsMiddleware"&gt;&lt;code&gt;X-Frame-Options  middleware&lt;/code&gt;&lt;/a&gt;  which in a supporting browser can prevent a site from being rendered inside a frame. It is possible to disable the protection on a per view basis or to configure the exact header value sent.&lt;/p&gt;

&lt;p&gt;The middleware is strongly recommended for any site that does not need to have its pages wrapped in a frame by third party sites, or only needs to allow that for a small section of the site.&lt;/p&gt;

&lt;h1&gt;
  
  
  Gateways in Django:
&lt;/h1&gt;

&lt;p&gt;WSGI and ASGI are both Python web application programming interfaces (APIs) that allow you to create web applications using Python. WSGI was the first widely adopted API for Python web applications, and it is still in use today. ASGI is a newer API that is designed to be more efficient and scalable than WSGI.&lt;/p&gt;

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

&lt;p&gt;WSGI stands for Web Server Gateway Interface. It is a specification that defines how a web server communicates with a Python web application. WSGI applications are typically written as a set of functions that handle requests and return responses. The web server calls these functions in response to incoming requests.&lt;/p&gt;

&lt;p&gt;WSGI is a synchronous API, which means that the web server blocks while it is waiting for the Python application to return a response. This can lead to performance problems in applications that handle a lot of concurrent requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ASGI&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;ASGI stands for Asynchronous Server Gateway Interface. It is a newer API that is designed to be more efficient and scalable than WSGI. ASGI applications are typically written using asynchronous programming techniques. This allows the web server to continue handling other requests while the Python application is processing a request.&lt;/p&gt;

&lt;p&gt;ASGI is a more flexible API than WSGI. It supports a wider range of web servers and Python web frameworks. ASGI is also more future-proof than WSGI. It is designed to support new technologies, such as WebSockets.&lt;/p&gt;

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

&lt;p&gt;Django is a popular Python web framework. Django supports both WSGI and ASGI. Django applications that use WSGI are typically deployed using a web server such as Gunicorn or uWSGI. Django applications that use ASGI are typically deployed using a web server such as Daphne or Hypercorn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Which API should you use?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are creating a new Python web application, you should use ASGI. ASGI is the more modern API and it offers a number of advantages over WSGI. If you are already using WSGI and you are happy with the performance, you can continue using WSGI. However, if you are experiencing performance problems, you should consider migrating your application to ASGI.&lt;/p&gt;

&lt;p&gt;Here is a table that summarizes the key differences between WSGI and ASGI&lt;/p&gt;

&lt;h3&gt;
  
  
  What is ondelete Cascade in models in django?
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;on_delete&lt;/code&gt; option in Django's &lt;code&gt;models.py&lt;/code&gt; file is used to specify what should happen to a model instance when the model instance that it is related to is deleted. The &lt;code&gt;on_delete&lt;/code&gt; option can be set to one of the following values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;CASCADE&lt;/code&gt;: When the parent model instance is deleted, all of the child model instances that are related to it will also be deleted.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;PROTECT&lt;/code&gt;: When the parent model instance is deleted, the delete operation will be prevented if any child model instances are related to it.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;SET_NULL&lt;/code&gt;: When the parent model instance is deleted, the foreign key field in the child model instances will be set to  &lt;code&gt;NULL&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;SET_DEFAULT&lt;/code&gt;: When the parent model instance is deleted, the foreign key field in the child model instances will be set to the default value.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;SET(...)&lt;/code&gt;: When the parent model instance is deleted, the foreign key field in the child model instances will be set to a custom value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;on_delete&lt;/code&gt; option is a powerful tool that can be used to maintain the integrity of your database. However, it is important to use it carefully, as it can also lead to data loss if it is not used correctly.&lt;/p&gt;

&lt;p&gt;Here is an example of how the &lt;code&gt;on_delete&lt;/code&gt; option can be used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Post(models.Model):
    title = models.CharField(max_length=255)
    body = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['-created_at']

class Comment(models.Model):
    post = models.ForeignKey(Post, on_delete=models.CASCADE)
    author = models.CharField(max_length=255)
    body = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Fields&lt;/strong&gt;  are used to store data in your models. They can be used to store simple data types, such as strings and numbers, or more complex data types, such as lists and dictionaries.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Validators&lt;/strong&gt;  are used to validate data before it is stored in your models. They can be used to check for things like invalid characters, empty values, and out-of-range values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are some of the most commonly used fields and validators in Django:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;CharField&lt;/strong&gt;  is used to store a string of text. It has a max_length argument that can be used to limit the length of the string.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;TextField&lt;/strong&gt;  is used to store a long string of text. It does not have a max_length argument, so there is no limit to the length of the string.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;IntegerField&lt;/strong&gt;  is used to store an integer value. It has a min and max argument that can be used to limit the range of the integer.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;FloatField&lt;/strong&gt;  is used to store a floating-point value. It has a min and max argument that can be used to limit the range of the floating-point value.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;BooleanField&lt;/strong&gt;  is used to store a boolean value. It can be set to True or False.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;DateField&lt;/strong&gt;  is used to store a date value. It can be set to a specific date or to the current date.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;DateTimeField&lt;/strong&gt;  is used to store a date and time value. It can be set to a specific date and time or to the current date and time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are some of the most commonly used validators in Django:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;MinLengthValidator&lt;/strong&gt;  is used to check that the value is not shorter than a certain length.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;MaxLengthValidator&lt;/strong&gt;  is used to check that the value is not longer than a certain length.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;EmailValidator&lt;/strong&gt;  is used to check that the value is a valid email address.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;URLValidator&lt;/strong&gt;  is used to check that the value is a valid URL.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;RegexValidator&lt;/strong&gt;  is used to check that the value matches a specific regular expression.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also write your own custom validators. To do this, you need to create a class that inherits from the &lt;code&gt;django.core.validators.Validator&lt;/code&gt; class. Your class must define a &lt;code&gt;validate()&lt;/code&gt; method that takes the value to be validated as its argument.&lt;/p&gt;

&lt;p&gt;Fields and validators are a powerful way to ensure that the data in your models is valid. By using them, you can help to prevent errors and make your applications more robust.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding the difference between Python module and Python class?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Modules&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A module is a self-contained unit of code that can be imported into another module. Modules are typically used to organize code and to share code between different applications. For example, you might have a module that contains code for performing mathematical operations, and you might have another module that contains code for performing string manipulation operations. You could then import these modules into your application and use the code in them to perform the desired operations.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Classes&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A class is a blueprint for creating objects. Classes define the properties and methods of an object. Properties are data that is associated with an object, and methods are actions that an object can perform. For example, you might have a class that represents a car. The class could define properties such as the car's make, model, and year, and it could define methods such as start_engine, drive, and stop. You could then create objects that are instances of the car class. Each object would have its own set of properties, and it could perform the actions defined by the methods in the class.&lt;/p&gt;

&lt;h3&gt;
  
  
  ## Using ORM queries in Django Shell
&lt;/h3&gt;

&lt;p&gt;Sure, you can use ORM queries in the Django shell to interact with your database. The Django shell is a Python interpreter that is pre-loaded with all of the Django models and functions. This makes it easy to write and test ORM queries without having to start a web server.&lt;/p&gt;

&lt;p&gt;To use the Django shell, you need to first start it. You can do this by running the following command:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py shell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the Django shell is started, you can import the models that you want to use. For example, if you have a model called &lt;code&gt;User&lt;/code&gt;, you would import it like this:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from myapp.models import User
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have imported the models, you can start writing ORM queries. ORM queries are written in Python, and they use the same syntax as SQL queries. For example, the following query will select all of the users from the database:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;users = User.objects.all(
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;users&lt;/code&gt; variable will now contain a list of all of the users in the database. You can then iterate through the list to access the individual users. For example, the following code will print the name of the first user in the list:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for user in users:
    print(user.name)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use ORM queries to filter and sort the results. For example, the following query will select all of the users who are active:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;active_users = User.objects.filter(is_active=True)

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;active_users&lt;/code&gt; variable will now contain a list of all of the active users in the database. You can also sort the results by any field. For example, the following query will sort the users by their name:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sorted_users = User.objects.order_by('name')

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;sorted_users&lt;/code&gt; variable will now contain a list of all of the users in the database, sorted by their name.&lt;/p&gt;

&lt;h3&gt;
  
  
  ## Turning ORM to SQL in Django Shell
&lt;/h3&gt;

&lt;p&gt;Sure, you can turn ORM queries to SQL in the Django shell by using the &lt;code&gt;.query&lt;/code&gt; attribute. The &lt;code&gt;.query&lt;/code&gt; attribute returns a &lt;code&gt;QuerySet&lt;/code&gt; object, which is a representation of the SQL query that will be executed. You can then use the &lt;code&gt;.sql&lt;/code&gt; method to get the SQL query as a string.&lt;/p&gt;

&lt;p&gt;For example, the following code will select all of the users from the database and print the SQL query that will be executed:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from myapp.models import User

users = User.objects.all()

query = users.query

print(query.sql)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the &lt;code&gt;print&lt;/code&gt; statement will be the following SQL query:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users

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

&lt;/div&gt;



&lt;p&gt;You can also use the &lt;code&gt;.query&lt;/code&gt; attribute to modify the SQL query before it is executed. For example, the following code will select all of the users who are active and print the SQL query that will be executed:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from myapp.models import User

users = User.objects.filter(is_active=True)

query = users.query

print(query.sql)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the &lt;code&gt;print&lt;/code&gt; statement will be the following SQL query:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users WHERE is_active = 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ## What are Aggregations in django?
&lt;/h3&gt;

&lt;p&gt;Sure, here's what you need to know about Aggregations in Django:&lt;/p&gt;

&lt;p&gt;In Django, aggregations are used to perform calculations on data. They can be used to find the total, average, minimum, maximum, or count of data in a QuerySet.&lt;/p&gt;

&lt;p&gt;There are a number of different aggregations that can be used in Django. Some of the most common aggregations include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Count():&lt;/strong&gt;  This aggregation returns the number of objects in a QuerySet.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Sum():&lt;/strong&gt;  This aggregation returns the sum of the values in a field.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Avg():&lt;/strong&gt;  This aggregation returns the average of the values in a field.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Min():&lt;/strong&gt;  This aggregation returns the minimum value in a field.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Max():&lt;/strong&gt;  This aggregation returns the maximum value in a field.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To use an aggregation, you can use the &lt;code&gt;aggregate()&lt;/code&gt; method on a QuerySet. The &lt;code&gt;aggregate()&lt;/code&gt; method takes a dictionary as its argument. The keys of the dictionary are the names of the aggregations that you want to use, and the values of the dictionary are the arguments that you want to pass to the aggregations.&lt;/p&gt;

&lt;p&gt;For example, the following code will find the total number of users in the database:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.db.models import Count

users = User.objects.all()

total_users = users.aggregate(Count('id'))['id__count']

print(total_users)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What are Annotations in django
&lt;/h3&gt;

&lt;p&gt;Annotations in Django are a way to add additional data to each object in a QuerySet. They are similar to aggregations, but they are applied to each object in the QuerySet, rather than the entire QuerySet as a whole.&lt;/p&gt;

&lt;p&gt;To use annotations, you can use the &lt;code&gt;annotate()&lt;/code&gt; method on a QuerySet. The &lt;code&gt;annotate()&lt;/code&gt; method takes a dictionary as its argument. The keys of the dictionary are the names of the annotations that you want to use, and the values of the dictionary are the expressions that you want to use to calculate the annotations.&lt;/p&gt;

&lt;p&gt;For example, the following code will add a new field called &lt;code&gt;total_orders&lt;/code&gt; to each user object in the QuerySet:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.db.models import Count

users = User.objects.all()

users = users.annotate(total_orders=Count('orders'))

for user in users:
    print(user.total_orders)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What is a migration file? Why is it needed?
&lt;/h3&gt;

&lt;p&gt;Django, a migration file is a Python file that describes the changes that need to be made to a database schema. Migration files are used to keep the database schema in sync with the Django models.&lt;/p&gt;

&lt;p&gt;Migration files are needed because Django models are defined in Python, but databases are defined in SQL. Migration files bridge the gap between these two languages by providing a way to describe the changes that need to be made to the database schema in Python.&lt;/p&gt;

&lt;p&gt;When you make changes to your Django models, you need to create a new migration file that describes the changes. You can then use the &lt;code&gt;migrate&lt;/code&gt; command to apply the changes to the database.&lt;/p&gt;

&lt;p&gt;Migration files are also used to roll back changes to the database schema. If you make a change to your Django models that you don't like, you can use the &lt;code&gt;revert&lt;/code&gt; command to roll back the changes to the previous migration.&lt;/p&gt;

&lt;p&gt;Migration files are a powerful tool that can help you keep your database schema in sync with your Django models. They are a valuable part of the Django development process.&lt;/p&gt;

&lt;p&gt;Here are some of the benefits of using migration files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;They help to keep your database schema in sync with your Django models.&lt;/strong&gt;  This can help to prevent errors and data loss.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;They make it easy to roll back changes to the database schema.&lt;/strong&gt;  This can be helpful if you make a mistake or if you need to revert to a previous version of the database.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;They can be used to automate the creation and deployment of database schemas.&lt;/strong&gt;  This can save you time and effort.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are using Django, I recommend that you use migration files to manage your database schema. They are a valuable tool that can help you to develop and deploy your Django applications more effectively.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are SQL transactions? (non ORM concept)
&lt;/h3&gt;

&lt;p&gt;In SQL, a transaction is a set of operations that are performed together as a unit. Transactions are used to ensure that data is always consistent in the database.&lt;/p&gt;

&lt;p&gt;There are four properties of transactions that are known as ACID:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Atomicity:&lt;/strong&gt;  All of the operations in a transaction must be completed successfully, or none of them can be completed.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Consistency:&lt;/strong&gt;  The database must be in a consistent state before and after the transaction is completed.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Isolation:&lt;/strong&gt;  Transactions should not interfere with each other.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Durability:&lt;/strong&gt;  Once a transaction is completed, the changes made to the database should be permanent.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Transactions are implemented using locks. A lock is a mechanism that prevents other transactions from accessing data that is being modified by a transaction.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are atomic transactions?
&lt;/h3&gt;

&lt;p&gt;An atomic transaction is a set of database operations that are treated as a single, indivisible unit. This means that either all of the operations in the transaction are performed successfully, or none of them are performed.&lt;/p&gt;

&lt;p&gt;Atomicity is one of the four ACID properties of transactions, which also include consistency, isolation, and durability.&lt;/p&gt;

&lt;p&gt;Atomicity is important for ensuring the integrity of data in a database. If a transaction is not atomic, it is possible for the database to be left in an inconsistent state. For example, if a transaction withdraws money from one account and deposits it into another, but the withdrawal fails, the account from which the money was withdrawn will be left with less money than it had before.&lt;/p&gt;

&lt;p&gt;Atomic transactions are implemented using locks. When a transaction starts, it acquires locks on the data that it needs to modify. This prevents other transactions from accessing the data until the current transaction finishes.&lt;/p&gt;

&lt;p&gt;If a transaction fails, the locks that it acquired are released. This allows other transactions to access the data again.&lt;/p&gt;

&lt;p&gt;Atomic transactions are a fundamental concept of database management systems. They are used to ensure the integrity of data in databases, and they are a key part of many database applications.&lt;/p&gt;

&lt;p&gt;Here are some examples of atomic transactions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Transferring money from one bank account to another:&lt;/strong&gt;  This transaction involves two operations: withdrawing money from one account and depositing it into another. If either of these operations fails, the transaction will fail and the money will not be transferred.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Updating a customer's record:&lt;/strong&gt;  This transaction involves two operations: updating the customer's name and updating the customer's address. If either of these operations fails, the transaction will fail and the customer's record will not be updated.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Deleting a product from an inventory system:&lt;/strong&gt;  This transaction involves one operation: deleting the product from the inventory system. If this operation fails, the product will not be deleted from the inventory system.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Atomic transactions provide a number of benefits, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Data integrity:&lt;/strong&gt;  Atomic transactions ensure that data is always consistent in the database. This is important for applications that need to maintain accurate data.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Data reliability:&lt;/strong&gt;  Atomic transactions help to protect data from corruption. If a transaction fails, the database will be rolled back to the state it was in before the transaction started.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Data availability:&lt;/strong&gt;  Atomic transactions can help to improve data availability. If a transaction fails, other transactions will not be blocked. This can help to improve the performance of your database applications.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Asynchronous JavaScript Technical Paper</title>
      <dc:creator>Atchukola Naresh</dc:creator>
      <pubDate>Thu, 01 Jun 2023 09:33:33 +0000</pubDate>
      <link>https://dev.to/god7780/asychronous-javascript-technical-paper-2jjb</link>
      <guid>https://dev.to/god7780/asychronous-javascript-technical-paper-2jjb</guid>
      <description>&lt;h1&gt;
  
  
  Callbacks:
&lt;/h1&gt;

&lt;p&gt;What is a Callback&lt;br&gt;
Function?&lt;br&gt;
In JavaScript, a callback function is a function that is passed into another&lt;br&gt;
function as an argument. This function can then be invoked at a later stage&lt;br&gt;
of time.&lt;br&gt;
Since, in JavaScript, functions are objects, functions can be passed as&lt;br&gt;
arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printFirstName(firstname, cb){
console.log(firstname)
cb ('Rogers')
}
function printLastName(lastname) {
console.log(lastname)
}
printFirstName('Steve' printLastName )// callback
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const isEven = (n)=&amp;gt;{
return n%2==0
}
let printResult = (evenFn, num) =&amp;gt;{
const isNumEven = evenFn(num)
console.log(The number ${num} is an Even Number ${isNumEven} `)
}
printResult (isEven,16)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;callback functions is the one of the reson to call JavaScript as the Functional programming.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  -   Promises:
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What is a Promise in JavaScript?
&lt;/h2&gt;

&lt;p&gt;A  promise  in JavaScript is no different from a promise in real life. If you take a promise from me that I will bring you a bar of chocolate, there can be three cases here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; You are waiting for me to come (the promise is in a  PENDING  state)&lt;/li&gt;
&lt;li&gt; I bought you a bar of chocolate (the promise is in a  FULFILLED  state)&lt;/li&gt;
&lt;li&gt; The shop was closed, or due to any reason, the promise failed ( the promise goes to the  REJECTED  state).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Similarly, when you call an  asynchronous function, i.e., a function that might send a response in the future, you are actually taking a promise. At first, the promise remains in the  PENDING  state because no response has been received. After some time, when the response is received, there are two possible cases:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; We got a response (i.e., the promise goes to the  FULFILLED  state)&lt;/li&gt;
&lt;li&gt; We got an error and no response (the promise got  REJECTED)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;  Getting a response means the promise is in the  SETTLED  state. In other words, the promise is not in the  PENDING  state now, and it has been either  RESOLVED  or  REJECTED.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fscaler.com%2Ftopics%2Fimages%2Fwhat-is-a-promise-in-javascript.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fscaler.com%2Ftopics%2Fimages%2Fwhat-is-a-promise-in-javascript.webp" alt="What is a Promise in JavaScript"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;:::&lt;/p&gt;

&lt;h2&gt;
  
  
  How Promises Work
&lt;/h2&gt;

&lt;p&gt;In technical terms, a promise is an object that is returned as a response to an asynchronous function. It can be one of these four possible states:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; PENDING&lt;/li&gt;
&lt;li&gt; FULFILLED&lt;/li&gt;
&lt;li&gt; REJECTED&lt;/li&gt;
&lt;li&gt; SETTLED&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fscaler.com%2Ftopics%2Fimages%2Fpromise-pending-and-fullfilled.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fscaler.com%2Ftopics%2Fimages%2Fpromise-pending-and-fullfilled.webp" alt="promise pending and fulfilled"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fscaler.com%2Ftopics%2Fimages%2Fpromise-pending-and-rejected.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fscaler.com%2Ftopics%2Fimages%2Fpromise-pending-and-rejected.webp" alt="promise pending and rejected"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let us understand this in a bit more detail. The moment a  promise  is invoked, it goes to the  PENDING  state and waits for a  response  to come. We might get the correct response, which makes the promise FULFILLED, or we might get an error, i.e., the promise goes to the REJECTED state. A  promise  is said to be  SETTLED  if it is not in the  pending state, i.e., either the response has arrived or an error has occurred.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;  Once settled, a promise cannot be resettled.&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Create a promise that resolves after 1 second
let promise = new Promise(function(resolve, reject) {
  setTimeout(() =&amp;gt; resolve("done"), 1000);
});

// Chain promises together
promise.then(function(result) {
  return fetch("https://example.com/api/data");
}).then(function(response) {
  return response.json();
}).then(function(data) {
  // Do something with the data
});

// Handle errors
promise.catch(function(error) {
  // Handle the error
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  The first example creates a promise that resolves after 1 second. The  &lt;code&gt;new Promise()&lt;/code&gt;  constructor takes two arguments: a function that is called when the promise is resolved or rejected, and a function that is called when the promise is rejected. In this case, the  &lt;code&gt;resolve()&lt;/code&gt;  function is called after 1 second, which resolves the promise.&lt;/li&gt;
&lt;li&gt;  The second example chains promises together. The  &lt;code&gt;then()&lt;/code&gt;  method on a promise takes a function as an argument. This function is called when the promise is resolved, and it is passed the result of the promise. In this case, the  &lt;code&gt;then()&lt;/code&gt;  method is called twice. The first time, the function is called with the result of the first promise, which is the string "done". The second time, the function is called with the result of the second promise, which is the JSON data from the API.&lt;/li&gt;
&lt;li&gt;  The third example handles errors. The  &lt;code&gt;catch()&lt;/code&gt;  method on a promise takes a function as an argument. This function is called when the promise is rejected, and it is passed the error object. In this case, the  &lt;code&gt;catch()&lt;/code&gt;  method is called if the promise is rejected for any reason.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Promises are a powerful tool for asynchronous programming in JavaScript. They allow you to write code that is more concise, readable, and maintainable.&lt;/p&gt;

&lt;h1&gt;
  
  
  -   Code Control:
&lt;/h1&gt;

&lt;p&gt;Asynchronous JavaScript code control is the process of managing the execution of asynchronous JavaScript code. This can be done using a variety of techniques, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Callbacks:&lt;/strong&gt;  Callbacks are functions that are passed as arguments to other functions and are called when those functions complete. This is a common technique for asynchronous code, as it allows the caller to specify what should happen when the asynchronous operation completes.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Promises:&lt;/strong&gt;  Promises are objects that represent the outcome of an asynchronous operation. They can be used to chain together asynchronous operations and to handle errors.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;async/await:&lt;/strong&gt;  async/await are new JavaScript keywords that make it easier to write asynchronous code. They allow you to write code that looks like synchronous code, but that actually executes asynchronously.
The best technique for asynchronous JavaScript code control depends on the specific needs of the application. Callbacks are a simple and straightforward way to control asynchronous code, but they can be difficult to manage when there are multiple callbacks nested together. Promises are a more powerful tool that can be used to chain together asynchronous operations and to handle errors. async/await is the newest technique, and it offers the most concise and readable syntax for asynchronous code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an example of how to use callbacks to control asynchronous code:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function doSomethingAsync(callback) {
  // Do something asynchronous here...
  callback();
}

doSomethingAsync(function() {
  // This code will be executed when the asynchronous operation completes.
});

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

&lt;/div&gt;



&lt;p&gt;Here is an example of how to use promises to control asynchronous code:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function doSomethingAsync() {
  // Do something asynchronous here...
  return new Promise(function(resolve, reject) {
    if (somethingSuccess) {
      resolve();
    } else {
      reject();
    }
  });
}

doSomethingAsync().then(function() {
  // This code will be executed when the asynchronous operation completes successfully.
}).catch(function() {
  // This code will be executed when the asynchronous operation fails.
});

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

&lt;/div&gt;



&lt;p&gt;Here is an example of how to use async/await to control asynchronous code:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function doSomethingAsync() {
  // Do something asynchronous here...
  const result = await something;
  // Use the result here...
}

doSomethingAsync();

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

&lt;/div&gt;



&lt;p&gt;Asynchronous JavaScript code control is an important skill for any JavaScript developer. By understanding the different techniques available, you can write code that is both efficient and easy to maintain.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript Technical Paper</title>
      <dc:creator>Atchukola Naresh</dc:creator>
      <pubDate>Tue, 30 May 2023 04:50:20 +0000</pubDate>
      <link>https://dev.to/god7780/javascript-technical-paper-3cj0</link>
      <guid>https://dev.to/god7780/javascript-technical-paper-3cj0</guid>
      <description>&lt;h1&gt;
  
  
  For loop:
&lt;/h1&gt;

&lt;p&gt;A for loop in JavaScript is a control flow statement that allows you to execute a block of code repeatedly until a specified condition is met.&lt;br&gt;
Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (initialization; condition; iteration) {
  // block of code to be executed repeatedly
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A for loop in JavaScript is a control flow statement that allows you to execute a block of code repeatedly until a specified condition is met. The syntax for a for loop is as follows:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (initialization; condition; iteration) {
  // block of code to be executed repeatedly
}

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;initialization&lt;/code&gt; expression is executed once, before the first iteration of the loop. The &lt;code&gt;condition&lt;/code&gt; expression is evaluated before each iteration of the loop. If the condition evaluates to &lt;code&gt;true&lt;/code&gt;, the block of code is executed. If the condition evaluates to &lt;code&gt;false&lt;/code&gt;, the loop terminates. The &lt;code&gt;iteration&lt;/code&gt; expression is executed after each iteration of the loop.&lt;/p&gt;

&lt;p&gt;Here is an example of a for loop that prints the numbers from 1 to 10:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (var i = 1; i &amp;lt;= 10; i++) {
  console.log(i);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This loop will first initialize the variable &lt;code&gt;i&lt;/code&gt; to 1. Then, it will evaluate the condition &lt;code&gt;i &amp;lt;= 10&lt;/code&gt;. Since &lt;code&gt;i&lt;/code&gt; is equal to 1, the condition evaluates to &lt;code&gt;true&lt;/code&gt;. The block of code is then executed, which prints the value of &lt;code&gt;i&lt;/code&gt; to the console. The loop then increments &lt;code&gt;i&lt;/code&gt; by 1 and repeats the process. This will continue until &lt;code&gt;i&lt;/code&gt; is greater than 10, at which point the condition will evaluate to &lt;code&gt;false&lt;/code&gt; and the loop will terminate.&lt;/p&gt;

&lt;h3&gt;
  
  
  forEach :
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;forEach()&lt;/code&gt; method in JavaScript is used to iterate over an array and execute a function for each element in the array.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;forEach()&lt;/code&gt; method is a convenient way to iterate over an array and execute a function for each element. It is often used to perform simple tasks, such as logging the elements of an array to the console or updating the values of an array.&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Log the elements of an array to the console.
const arr = [1, 2, 3, 4, 5];

arr.forEach(function(element) {
  console.log(element);
});

// Update the values of an array.
const arr = [1, 2, 3, 4, 5];

arr.forEach(function(element) {
  element *= 2;
});

console.log(arr); // [2, 4, 6, 8, 10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  for (...in..):
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;for ... in&lt;/code&gt; loop in JavaScript is used to iterate over the properties of an object. It can be used to print the properties of an object, or to access the values of the properties. The syntax for the &lt;code&gt;for ... in&lt;/code&gt; loop is as follows:&lt;br&gt;
Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let key in object) {
  // Do something with the key and the value of object[key]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const object = {
  name: "John Doe",
  age: 30,
  address: "123 Main Street"
};

for (let key in object) {
  console.log(key, object[key]);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will print the following output:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name John Doe
age 30
address 123 Main Street
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  for (..of..):
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;for ... of&lt;/code&gt; loop in JavaScript is used to iterate over the values of an iterable object. It can be used to print the values of an iterable object, or to access the values of the iterable object. The syntax for the &lt;code&gt;for ... of&lt;/code&gt; loop is as follows:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let value of iterable) {
  // Do something with the value
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const iterable = [1, 2, 3, 4, 5];

for (let value of iterable) {
  console.log(value);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will print the following output:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
2
3
4
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;for ... of&lt;/code&gt; loop can also be used to iterate over the values of a string. For example, the following code will print the characters in the string:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const string = "Hello, world!";

for (let value of string) {
  console.log(value);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will print the following output:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;H
e
l
l
o
,

w
o
r
l
d
!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  while loop:
&lt;/h1&gt;

&lt;p&gt;A while loop in JavaScript is a programming construct that allows you to execute a block of code repeatedly as long as a given condition is true.&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (condition) {
  // block of code to be executed repeatedly
}

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

&lt;/div&gt;



&lt;p&gt;Here is an example of a while loop that prints the numbers from 1 to 10:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var i = 1;
while (i &amp;lt;= 10) {
  console.log(i);
  i++;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Mutable and Immutable Methods (in strings);
&lt;/h1&gt;

&lt;p&gt;In JavaScript, strings are immutable, which means that once a string is created, its value cannot be changed. This is in contrast to mutable objects, such as arrays, which can be changed after they are created.&lt;/p&gt;

&lt;p&gt;There are a number of methods in JavaScript that can be used to manipulate strings. Some of these methods are mutable, while others are immutable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mutable methods&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;concat()&lt;/code&gt;: This method concatenates the specified string to the end of the current string.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;replace()&lt;/code&gt;: This method replaces all occurrences of the specified substring with the specified replacement string.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;slice()&lt;/code&gt;: This method returns a new string that is a substring of the current string.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Immutable methods&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;toUpperCase()&lt;/code&gt;: This method returns a new string that is the uppercase version of the current string.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;toLowerCase()&lt;/code&gt;: This method returns a new string that is the lowercase version of the current string.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;trim()&lt;/code&gt;: This method returns a new string that has all leading and trailing whitespace characters removed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is important to be aware of the difference between mutable and immutable methods when working with strings. If you are using a mutable method, you should be careful not to modify the string in a way that could affect other parts of your code.&lt;/p&gt;

&lt;h1&gt;
  
  
  Mutable and Immutable Methods (in arrays):
&lt;/h1&gt;

&lt;p&gt;In JavaScript, arrays are mutable objects, which means that their contents can be changed after they have been created. This is done by using the various array methods, such as &lt;code&gt;push()&lt;/code&gt;, &lt;code&gt;pop()&lt;/code&gt;, &lt;code&gt;shift()&lt;/code&gt;, &lt;code&gt;unshift()&lt;/code&gt;, &lt;code&gt;reverse()&lt;/code&gt;, &lt;code&gt;sort()&lt;/code&gt;, and &lt;code&gt;splice()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mutable Array Methods&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;push()&lt;/code&gt;: Adds an element to the end of the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;pop()&lt;/code&gt;: Removes the last element from the array and returns it.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;shift()&lt;/code&gt;: Removes the first element from the array and returns it.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;unshift()&lt;/code&gt;:  Adds an element to the beginning of the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;reverse()&lt;/code&gt;: Reverses the order of the elements in the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;sort()&lt;/code&gt;: Sorts the elements in the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;splice()&lt;/code&gt;: Removes and/or adds elements from the array.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Immutable Array Methods&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are also a number of immutable array methods that do not mutate the original array. These methods return a new array with the changes applied.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;map()&lt;/code&gt;: Applies a function to each element in the array and returns a new array with the results.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;filter()&lt;/code&gt;: Filters the array by returning only the elements that meet a certain condition.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;reduce()&lt;/code&gt;: Reduces the array to a single value by applying a function to each element.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JavaScript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function swap(a, b) {
  const temp = a;
  a = b;
  b = temp;
}

const x = 1;
const y = 2;

swap(x, y);

console.log(x, y); // 2, 1

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

&lt;/div&gt;



&lt;p&gt;Use code with caution.  &lt;a href="https://bard.google.com/faq#coding"&gt;Learn more&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;content_copy&lt;/p&gt;

&lt;p&gt;In this example, the &lt;code&gt;swap()&lt;/code&gt; function takes two arguments: &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;. The &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; arguments are references to the variables &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;. When the &lt;code&gt;swap()&lt;/code&gt; function is called, the values of &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are swapped. The changes to &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are reflected in the calling function, because &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are references to the variables &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  -   Pass by Reference and Pass by Value - add codeblocks;
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Pass by reference&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function swap(a, b) {
  const temp = a;
  a = b;
  b = temp;
}

const x = 1;
const y = 2;

swap(x, y);

console.log(x, y); // 2, 1

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

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;swap()&lt;/code&gt; function takes two arguments: &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;. The &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; arguments are references to the variables &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;. When the &lt;code&gt;swap()&lt;/code&gt; function is called, the values of &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are swapped. The changes to &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are reflected in the calling function, because &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are references to the variables &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;.&lt;br&gt;
&lt;strong&gt;Pass by value&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function add(a, b) {
  return a + b;
}

const x = 1;
const y = 2;

const z = add(x, y);

console.log(z); // 3

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

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;add()&lt;/code&gt; function takes two arguments: &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;. The &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; arguments are the values of the variables &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;. When the &lt;code&gt;add()&lt;/code&gt; function is called, the values of &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are added together and the result is returned. The changes to &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are not reflected in the calling function, because &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are the values of the variables &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In general, pass by reference is used when you want to modify the value of an argument in the calling function. Pass by value is used when you only want to use the value of an argument in the called function.&lt;/p&gt;

&lt;h1&gt;
  
  
  Array methods - add codeblocks and mention mutable/immutable;
&lt;/h1&gt;

&lt;h4&gt;
  
  
  Array.pop-
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;array.pop()&lt;/code&gt; method in JavaScript is used to remove the last element from an array and returns that element. This method changes the length of the array so it was a&lt;br&gt;
mutable method.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;array.pop()&lt;/code&gt; method takes no arguments.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use the &lt;code&gt;array.pop()&lt;/code&gt; method:&lt;/p&gt;

&lt;p&gt;JavaScript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];

const lastNumber = numbers.pop();

console.log(lastNumber); // 5

console.log(numbers); // [1, 2, 3, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Array.push:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;array.push()&lt;/code&gt; method in JavaScript is used to add one or more elements to the end of an array. This method changes the length of the array.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;array.push()&lt;/code&gt; method takes one or more arguments, which are the elements to be added to the end of the array.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use the &lt;code&gt;array.push()&lt;/code&gt; method:&lt;/p&gt;

&lt;p&gt;JavaScript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3];

numbers.push(4, 5);

console.log(numbers); // [1, 2, 3, 4, 5]

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  -   Array.concat:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;array.concat()&lt;/code&gt; method in JavaScript is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;array.concat()&lt;/code&gt; method takes one or more arguments, which are the arrays to be merged.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use the &lt;code&gt;array.concat()&lt;/code&gt; method:&lt;/p&gt;

&lt;p&gt;JavaScript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers1 = [1, 2, 3];
const numbers2 = [4, 5, 6];

const numbers3 = numbers1.concat(numbers2);

console.log(numbers3); // [1, 2, 3, 4, 5, 6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  -   Array.slice:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;array.slice()&lt;/code&gt; method in JavaScript is used to extract a portion of an array into a new array. This method does not change the original array, but instead returns a new array.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;array.slice()&lt;/code&gt; method takes three arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The start index of the portion to be extracted.&lt;/li&gt;
&lt;li&gt;  The end index of the portion to be extracted.&lt;/li&gt;
&lt;li&gt;  The optional third argument is a boolean value that indicates whether or not to include the end index in the extracted portion. If the third argument is omitted or false, the end index is not included in the extracted portion.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an example of how to use the &lt;code&gt;array.slice()&lt;/code&gt; method:&lt;/p&gt;

&lt;p&gt;JavaScript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];

const numbers2 = numbers.slice(1, 3);

console.log(numbers2); // [2, 3]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  -   Array.splice:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;array.splice()&lt;/code&gt; method in JavaScript is used to remove, add, or replace elements in an array. This method changes the original array, and returns the removed elements as a new array.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;array.splice()&lt;/code&gt; method takes four arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The index of the first element to be removed, added, or replaced.&lt;/li&gt;
&lt;li&gt;  The number of elements to be removed.&lt;/li&gt;
&lt;li&gt;  The elements to be added, or an empty array if no elements are to be added.&lt;/li&gt;
&lt;li&gt;  An optional fifth argument that indicates whether or not to return the removed elements. If the fifth argument is omitted or false, the removed elements are not returned.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an example of how to use the &lt;code&gt;array.splice()&lt;/code&gt; method to remove elements from an array:&lt;/p&gt;

&lt;p&gt;JavaScript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];

numbers.splice(1, 2);

console.log(numbers); // [1, 4 ,5]

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

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;array.splice()&lt;/code&gt; method is called on the &lt;code&gt;numbers&lt;/code&gt; array. The &lt;code&gt;array.splice()&lt;/code&gt; method removes the elements at index 1 and 2, inclusive. The &lt;code&gt;numbers&lt;/code&gt; array is then logged to the console. The &lt;code&gt;numbers&lt;/code&gt; array now only contains the numbers 1 ,4, 5.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use the &lt;code&gt;array.splice()&lt;/code&gt; method to add elements to an array:&lt;/p&gt;

&lt;p&gt;JavaScript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];

numbers.splice(2, 0, 6, 7);

console.log(numbers); // [1, 2, 6, 7, 3, 4, 5]

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

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;array.splice()&lt;/code&gt; method is called on the &lt;code&gt;numbers&lt;/code&gt; array. The &lt;code&gt;array.splice()&lt;/code&gt; method adds the numbers 6 and 7 at index 2. The &lt;code&gt;numbers&lt;/code&gt; array is then logged to the console. The &lt;code&gt;numbers&lt;/code&gt; array now contains the numbers 1, 2, 6, 7, 3, 4, and 5.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use the &lt;code&gt;array.splice()&lt;/code&gt; method to replace elements in an array:&lt;/p&gt;

&lt;p&gt;JavaScript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];

numbers.splice(2, 1, 6);

console.log(numbers); // [1, 2, 6, 4, 5]

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

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;array.splice()&lt;/code&gt; method is called on the &lt;code&gt;numbers&lt;/code&gt; array. The &lt;code&gt;array.splice()&lt;/code&gt; method replaces the element at index 2 with the number 6. The &lt;code&gt;numbers&lt;/code&gt; array is then logged to the console. The &lt;code&gt;numbers&lt;/code&gt; array now contains the numbers 1, 2, 6, 4, and 5.&lt;/p&gt;

&lt;h4&gt;
  
  
  -   Array.join:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;Array.join()&lt;/code&gt; method in JavaScript is used to join the elements of an array into a string. The elements of the string will be separated by a specified separator and its default value is a comma(, ).&lt;/p&gt;

&lt;p&gt;The syntax for the &lt;code&gt;Array.join()&lt;/code&gt; method is:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.join(separator)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;array&lt;/code&gt;  is the array to be joined&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;separator&lt;/code&gt;  is the string that will be used to separate the elements of the array. If no separator is specified, a comma will be used by default.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, the following code will join the elements of the &lt;code&gt;array&lt;/code&gt; variable into a string, separated by commas:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 2, 3, 4];
const joinedArray = array.join(',');

console.log(joinedArray); // "1,2,3,4"

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Array.join()&lt;/code&gt; method can also be used to join the elements of an array into a string, separated by a custom separator. For example, the following code will join the elements of the &lt;code&gt;array&lt;/code&gt; variable into a string, separated by spaces:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = ['Hello', 'World'];
const joinedArray = array.join(' ');

console.log(joinedArray); // "Hello World"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  -   Array.flat:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;Array.flat()&lt;/code&gt; method in JavaScript is used to flatten an array. This means that it will combine all of the sub-arrays in the original array into a single, flat array.&lt;/p&gt;

&lt;p&gt;The syntax for the &lt;code&gt;Array.flat()&lt;/code&gt; method is:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.flat([depth])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;array&lt;/code&gt;  is the array to be flattened&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;depth&lt;/code&gt;  is an optional parameter that specifies the maximum depth of the sub-arrays to be flattened. If no depth is specified, all sub-arrays will be flattened.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, the following code will flatten the &lt;code&gt;array&lt;/code&gt; variable:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 2, [3, 4], [5, 6]];
const flatArray = array.flat();

console.log(flatArray); // [1, 2, 3, 4, 5, 6]

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Array.find:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;Array.find()&lt;/code&gt; method in JavaScript is used to find the first element in an array that satisfies a given condition. The method takes a callback function as an argument, and the callback function is called once for each element in the array. If the callback function returns a truthy value for any element, the &lt;code&gt;Array.find()&lt;/code&gt; method returns that element. If the callback function never returns a truthy value, the &lt;code&gt;Array.find()&lt;/code&gt; method returns &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The syntax for the &lt;code&gt;Array.find()&lt;/code&gt; method is:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.find(callback)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;array&lt;/code&gt;  is the array to be searched&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;callback&lt;/code&gt;  is a function that takes an element of the array as its argument and returns a truthy or falsy value&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, the following code will find the first element in the &lt;code&gt;array&lt;/code&gt; variable that is greater than 10:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const firstGreaterThan10 = array.find(element =&amp;gt; element &amp;gt; 10);

console.log(firstGreaterThan10); // 11
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  -   Array.indexOf:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;array.indexOf()&lt;/code&gt; method in JavaScript returns the first index of the element in the array if it is present at least once. Returns -1 if the element is not found in the array.&lt;/p&gt;

&lt;p&gt;The syntax for &lt;code&gt;array.indexOf()&lt;/code&gt; is:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.indexOf(element[, fromIndex])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;element&lt;/code&gt;  is the value to search for.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;fromIndex&lt;/code&gt;  is the index to start the search from. If not specified, the search starts at index 0.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 2, 3, 4, 5];

// Find the index of the first occurrence of 3
const index = array.indexOf(3);
console.log(index); // 2

// Find the index of the first occurrence of 6
const index = array.indexOf(6);
console.log(index); // -1

// Find the index of the first occurrence of 3, starting at index 2
const index = array.indexOf(3, 2);
console.log(index); // 3

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  -   Array.includes:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;Array.prototype.includes()&lt;/code&gt; method in JavaScript checks if an array contains a specified element or not.&lt;/p&gt;

&lt;p&gt;The syntax for &lt;code&gt;Array.prototype.includes()&lt;/code&gt; is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;element&lt;/code&gt;  is the value to search for.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;fromIndex&lt;/code&gt;  is the index to start the search from. If not specified, the search starts at index 0.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;includes()&lt;/code&gt; method returns &lt;code&gt;true&lt;/code&gt; if the element is found in the array, and &lt;code&gt;false&lt;/code&gt; if it is not found.&lt;/p&gt;

&lt;p&gt;Here are some examples of how to use &lt;code&gt;Array.prototype.includes()&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 2, 3, 4, 5];

// Check if the array includes 3
const includes3 = array.includes(3);
console.log(includes3); // true

// Check if the array includes 6
const includes6 = array.includes(6);
console.log(includes6); // false

// Check if the array includes 3, starting at index 2
const includes3FromIndex2 = array.includes(3, 2);
console.log(includes3FromIndex2); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  -   Array.findIndex:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;Array.findIndex()&lt;/code&gt; method in JavaScript is used to find the index of the first element in an array that satisfies a provided testing function. The method returns the index of the element that satisfies the testing function or -1 if no element passed the test.&lt;/p&gt;

&lt;p&gt;The syntax for the &lt;code&gt;Array.findIndex()&lt;/code&gt; method is as follows:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.findIndex(callback[, thisArg])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;array&lt;/code&gt;  is the array to be searched.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;callback&lt;/code&gt;  is a function that takes an element of the array as its input and returns a Boolean value. The function will be called for each element in the array, and the first time it returns a truthy value, the  &lt;code&gt;Array.findIndex()&lt;/code&gt;  method will return the index of that element.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;thisArg&lt;/code&gt;  is an optional value that will be used as the  &lt;code&gt;this&lt;/code&gt;  value inside the callback function. If  &lt;code&gt;thisArg&lt;/code&gt;  is not specified, the  &lt;code&gt;this&lt;/code&gt;  value will be  &lt;code&gt;undefined&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an example of how to use the &lt;code&gt;Array.findIndex()&lt;/code&gt; method:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [1, 2, 3, 4, 5];

const index = arr.findIndex(x =&amp;gt; x % 2 === 0);

console.log(index); // 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  -   Array.forEach:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;Array.forEach()&lt;/code&gt; method is an iterative method that calls a provided callback function once for each element in an array in ascending-index order. Unlike &lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;forEach()&lt;/code&gt; always returns &lt;code&gt;undefined&lt;/code&gt; and is not chainable. The typical use case is to execute side effects at the end of a chain.&lt;/p&gt;

&lt;p&gt;The callback function is called with the following arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;element&lt;/code&gt;: The current element being processed in the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;index&lt;/code&gt;: The index of the current element being processed in the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;array&lt;/code&gt;: The array &lt;code&gt;forEach()&lt;/code&gt; was called upon.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The callback function can modify the array, but it cannot change the length of the array.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use &lt;code&gt;Array.forEach()&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 2, 3, 4, 5];

array.forEach((element, index) =&amp;gt; {
  console.log(`The element at index ${index} is ${element}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Array.forEach()&lt;/code&gt; method is an iterative method that calls a provided callback function once for each element in an array in ascending-index order. Unlike &lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;forEach()&lt;/code&gt; always returns &lt;code&gt;undefined&lt;/code&gt; and is not chainable. The typical use case is to execute side effects at the end of a chain.&lt;/p&gt;

&lt;p&gt;The callback function is called with the following arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;element&lt;/code&gt;: The current element being processed in the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;index&lt;/code&gt;: The index of the current element being processed in the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;array&lt;/code&gt;: The array &lt;code&gt;forEach()&lt;/code&gt; was called upon.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The callback function can modify the array, but it cannot change the length of the array.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use &lt;code&gt;Array.forEach()&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 2, 3, 4, 5];

array.forEach((element, index) =&amp;gt; {
  console.log(`The element at index ${index} is ${element}`);
});

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

&lt;/div&gt;



&lt;p&gt;Use code with caution.  &lt;a href="https://bard.google.com/faq#coding"&gt;Learn more&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;content_copy&lt;/p&gt;

&lt;p&gt;This code will print the following to the console:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The element at index 0 is 1
The element at index 1 is 2
The element at index 2 is 3
The element at index 3 is 4
The element at index 4 is 5

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  -   Array.map:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;Array.map()&lt;/code&gt; method is an iterative method that creates a new array from the results of calling a provided function on every element in the calling array. The callback function is called with the following arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;element&lt;/code&gt;: The current element being processed in the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;index&lt;/code&gt;: The index of the current element being processed in the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;array&lt;/code&gt;: The array &lt;code&gt;map()&lt;/code&gt; was called  upon.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The callback function must return a value, which will be the corresponding element in the new array.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use &lt;code&gt;Array.map()&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 2, 3, 4, 5];

const newArray = array.map((element) =&amp;gt; {
  return element * 2;
});

console.log(newArray); // [2, 4, 6, 8, 10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  -   Array.filter:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;Array.filter()&lt;/code&gt; method is an iterative method that creates a new array from the elements of an existing array that pass a test implemented by a provided function. The callback function is called with the following arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;element&lt;/code&gt;: The current element being processed in the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;index&lt;/code&gt;: The index of the current element being processed in the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;array&lt;/code&gt;: The array  &lt;code&gt;filter()&lt;/code&gt;  was called upon.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The callback function must return a Boolean value, which will be used to determine whether the element is included in the new array. If the callback function returns &lt;code&gt;true&lt;/code&gt;, the element is included in the new array. If the callback function returns &lt;code&gt;false&lt;/code&gt;, the element is not included in the new array.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use &lt;code&gt;Array.filter()&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 2, 3, 4, 5];

const newArray = array.filter((element) =&amp;gt; {
  return element % 2 === 0;
});

console.log(newArray); // [2, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  -   Array.reduce:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;Array.reduce()&lt;/code&gt; method is a recursive method that applies a function to each element of an array, from left to right, and returns a single value. The callback function is called with the following arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;accumulator&lt;/code&gt;: The current value of the accumulator.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;element&lt;/code&gt;: The current element  being processed in the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;index&lt;/code&gt;: The index of the current element being processed in the array.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;array&lt;/code&gt;: The array &lt;code&gt;reduce()&lt;/code&gt; was called upon.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The callback function must return a value, which will be the new value of the accumulator.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use &lt;code&gt;Array.reduce()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 2, 3, 4, 5];

const sum = array.reduce((accumulator, element) =&amp;gt; {
  return accumulator + element;
}, 0);

console.log(sum); // 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  -   Array.sort:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;Array.sort()&lt;/code&gt; method in JavaScript is used to sort the elements of an array in place. By default, the sort() method sorts the array elements in ascending order with the smallest value first and largest value last. The sort() method casts elements to strings and compares the strings to determine the orders.&lt;/p&gt;

&lt;p&gt;The following is an example of how to use the &lt;code&gt;Array.sort()&lt;/code&gt; method to sort an array of numbers in ascending order:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [10, 5, 2, 1, 8, 7, 6, 3, 4, 9];

numbers.sort();

console.log(numbers); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  -   Array methods chaining:
&lt;/h1&gt;

&lt;p&gt;JavaScript chaining is a technique that allows you to call multiple methods on an object in a single statement. This can make your code more concise and easier to read.&lt;/p&gt;

&lt;p&gt;To chain methods, you simply separate the method names with periods (.). For example, the following code chains the &lt;code&gt;toUpperCase()&lt;/code&gt; and &lt;code&gt;slice()&lt;/code&gt; methods on the &lt;code&gt;str&lt;/code&gt; variable:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;str.toUpperCase().slice(0, 5);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will return the first five characters of &lt;code&gt;str&lt;/code&gt; in uppercase letters.&lt;/p&gt;

&lt;h1&gt;
  
  
  -   String methods - add codeblocks and mention mutable/immutable;
&lt;/h1&gt;

&lt;h4&gt;
  
  
  Mutable and Immutable Methods (in strings);
&lt;/h4&gt;

&lt;p&gt;In JavaScript, strings are immutable, which means that once a string is created, its value cannot be changed. This is in contrast to mutable objects, such as arrays, which can be changed after they are created.&lt;/p&gt;

&lt;p&gt;There are a number of methods in JavaScript that can be used to manipulate strings. Some of these methods are mutable, while others are immutable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mutable methods&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;concat()&lt;/code&gt;: This method concatenates the specified string to the end of the current string.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;replace()&lt;/code&gt;: This method replaces all occurrences of the specified substring with the specified replacement string.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;slice()&lt;/code&gt;: This method returns a new string that is a substring of the current string.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Immutable methods&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;toUpperCase()&lt;/code&gt;: This method returns a new string that is the uppercase version of the current string.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;toLowerCase()&lt;/code&gt;: This method returns a new string that is the lowercase version of the current string.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;trim()&lt;/code&gt;: This method returns a new string that has all leading and trailing whitespace characters removed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is important to be aware of the difference between mutable and immutable methods when working with strings. If you are using a mutable method, you should be careful not to modify the string in a way that could affect other parts of your code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;toLocaleUpperCase()&lt;/strong&gt;  : Converts a string to uppercase, based on the current locale.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const str = "Hello";
const uppercaseStr = str.toLocaleUpperCase(); // "HELLO"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;const str = "Hello"; &lt;br&gt;
const repeatedStr = str.repeat(3); // "HelloHelloHello"&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;trim()&lt;/strong&gt;  : Removes whitespace from the beginning and end of a string.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const str = "   Hello, world!   ";
const trimmedStr = str.trim(); // "Hello, world!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;substring()&lt;/strong&gt;  : Extracts a substring from a string.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const str = "Hello, world!";
const substring = str.substring(0, 5); // "Hello"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;split()&lt;/strong&gt;  : Splits a string into an array of substrings based on a delimiter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const str = "Hello, world!";
const arrayOfSubstrings = str.split(","); // ["Hello", "world!"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  **
slice()**  : Extracts a substring from a string.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const str = "Hello, world!";
const substring = str.slice(0, 5); // "Hello"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;replace()&lt;/strong&gt;  : Replaces all occurrences of a substring in a string with another string.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const str = "Hello, world!";
const newStr = str.replace("world", "universe"); // "Hello, universe!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;indexOf()&lt;/strong&gt;  : Returns the index of the first occurrence of a substring in a string.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const str = "Hello, world!";
const index = str.indexOf("world"); // 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;concat()&lt;/strong&gt;  : Concatenates two or more strings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const str1 = "Hello, ";
const str2 = "world!";
const combinedStr = str1.concat(str2); // "Hello, world!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  -   Object methods and operations - add codeblocks and mention mutable/immutable:
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;keys()&lt;/strong&gt;  : Returns an array of the object's property names.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = {
  name: "John Doe",
  age: 30
};

const propertyNames = Object.keys(obj); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;values()&lt;/strong&gt;  : Returns an array of the object's property values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = {
  name: "John Doe",
  age: 30
};

const propertyValues = Object.values(obj); // ["John Doe", 30]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;entries()&lt;/strong&gt;  : Returns an array of tuples, where each tuple contains a property name and its value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = {
  name: "John Doe",
  age: 30
};

const propertyEntries = Object.entries(obj); // [["name", "John Doe"], ["age", 30]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;get()&lt;/strong&gt;  : Returns the value of the object's property with the specified name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = {
  name: "John Doe",
  age: 30
};

const name = obj.get("name"); // "John Doe"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;set()&lt;/strong&gt;  : Sets the value of the object's property with the specified name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = {
  name: "John Doe"
};

obj.set("age", 30);

const age = obj.get("age"); // 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;deleteProperty()&lt;/strong&gt;  : Deletes the object's property with the specified name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = {
  name: "John Doe"
};

delete obj.name;

console.log(obj.name); // undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;toString()&lt;/strong&gt;  : Returns a string representation of the object.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = {
  name: "John Doe",
  age: 30
};

const stringRepresentation = obj.toString(); // "{name: 'John Doe', age: 30}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Hoisting in JS:
&lt;/h1&gt;

&lt;p&gt;Sure, hoisting in JavaScript is the process of moving all variable and function declarations to the top of their scope, before any code is executed. This means that even if you declare a variable or function below where it is used, it will still be available in the scope where it is used.&lt;/p&gt;

&lt;p&gt;For example, the following code will print "Hello, world!" even though the &lt;code&gt;greet()&lt;/code&gt; function is declared below the &lt;code&gt;console.log()&lt;/code&gt; statement:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet() {
  console.log("Hello, world!");
}

greet();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is because the &lt;code&gt;greet()&lt;/code&gt; function is hoisted to the top of the scope where it is defined.&lt;/p&gt;

&lt;p&gt;Hoisting can be a bit confusing at first, but it is an important concept to understand in JavaScript. By understanding hoisting, you can avoid errors in your code and write more efficient code.&lt;/p&gt;

&lt;p&gt;Here are some things to keep in mind about hoisting:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Only variable and function declarations are hoisted. Expressions are not hoisted.&lt;/li&gt;
&lt;li&gt;  Hoisting does not affect the order of execution of your code. The code will still be executed in the order in which it is written.&lt;/li&gt;
&lt;li&gt;  Hoisting can be used to your advantage. For example, you can use hoisting to declare variables that are only used in one part of your code. This can make your code more readable and easier to maintain.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Scopes:
&lt;/h1&gt;

&lt;p&gt;In JavaScript, a scope is a region of code where a variable is accessible. There are three types of scopes in JavaScript:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Global scope:&lt;/strong&gt;  The global scope is the outermost scope in a JavaScript program. Variables declared in the global scope are accessible from anywhere in the program.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Function scope:&lt;/strong&gt;  A function scope is created when a function is defined. Variables declared in a function scope are only accessible from within that function.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Block scope:&lt;/strong&gt;  A block scope is created when a block of code is enclosed in curly braces (&lt;code&gt;{}&lt;/code&gt;). Variables declared in a block scope are only accessible from within that block.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you declare a variable, the JavaScript engine will create a new entry in the current scope's symbol table. The symbol table is a data structure that stores information about all of the variables in a scope. When you access a variable, the JavaScript engine will look up the variable's name in the current scope's symbol table. If the variable is found, the engine will return the variable's value. If the variable is not found, the engine will throw an error.&lt;/p&gt;

&lt;p&gt;It is important to understand scopes in JavaScript in order to avoid errors in your code. For example, if you declare a variable in a function scope and then try to access it outside of the function, you will get an error.&lt;/p&gt;

&lt;p&gt;Here are some tips for using scopes in JavaScript:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Declare variables in the smallest scope possible.&lt;/strong&gt;  This will make your code more readable and easier to maintain.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Use descriptive variable names.&lt;/strong&gt;  This will help you to understand what each variable is used for.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Use the  &lt;code&gt;let&lt;/code&gt;  and  &lt;code&gt;const&lt;/code&gt;  keywords to declare variables.&lt;/strong&gt;  These keywords will help you to avoid errors caused by accidentally overwriting variables.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Closures:
&lt;/h1&gt;

&lt;p&gt;A closure is a function that has access to variables that are declared in an outer scope. This means that the function can access those variables even after the outer scope has closed. Closures are a powerful tool that can be used to create reusable code and to implement complex functionality.&lt;/p&gt;

&lt;p&gt;To create a closure, you need to define a function inside of another function. The inner function will have access to all of the variables that are declared in the outer function, even after the outer function has returned.&lt;/p&gt;

&lt;p&gt;For example, the following code defines a function called &lt;code&gt;makeCounter()&lt;/code&gt; that returns a function that increments a counter. The &lt;code&gt;makeCounter()&lt;/code&gt; function creates a closure around the &lt;code&gt;counter&lt;/code&gt; variable. This means that the &lt;code&gt;increment()&lt;/code&gt; function will be able to access the &lt;code&gt;counter&lt;/code&gt; variable even after the &lt;code&gt;makeCounter()&lt;/code&gt; function has returned.&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function makeCounter() {
  let counter = 0;

  function increment() {
    counter++;
    return counter;
  }

  return increment;
}

const counter = makeCounter();

console.log(counter()); // 1
console.log(counter()); // 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;increment()&lt;/code&gt; function is able to access the &lt;code&gt;counter&lt;/code&gt; variable because it is defined inside of the &lt;code&gt;makeCounter()&lt;/code&gt; function. The &lt;code&gt;makeCounter()&lt;/code&gt; function returns the &lt;code&gt;increment()&lt;/code&gt; function, which means that the &lt;code&gt;increment()&lt;/code&gt; function can be used outside of the &lt;code&gt;makeCounter()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Closures can be used to create reusable code. For example, you could define a function that takes a callback function as an argument. The callback function would then be able to access any variables that are declared in the outer function. This allows you to encapsulate functionality in a function and then reuse that functionality in other parts of your code.&lt;/p&gt;

&lt;p&gt;Closures can also be used to implement complex functionality. For example, you could use closures to create a timer function that keeps track of the time that has passed since the function was called. The timer function could then be used to implement features such as a countdown timer or a stopwatch.&lt;/p&gt;

&lt;p&gt;Closures are a powerful tool that can be used to create reusable code and to implement complex functionality. If you are not familiar with closures, I encourage you to learn more about them. They can be a valuable asset in your JavaScript toolkit.&lt;/p&gt;

&lt;h1&gt;
  
  
  -   Debugging:
&lt;/h1&gt;

&lt;p&gt;Debugging in JavaScript can be a challenge, but there are a number of tools and techniques that can help you find and fix errors in your code.&lt;/p&gt;

&lt;p&gt;One of the most basic debugging techniques is to use the &lt;code&gt;console.log()&lt;/code&gt; function to print the values of variables and expressions to the console. This can be helpful for tracking down the source of an error.&lt;/p&gt;

&lt;p&gt;Another useful debugging technique is to use breakpoints. Breakpoints allow you to pause the execution of your code at a specific point. This can be helpful for inspecting the values of variables and expressions at a specific point in the code.&lt;/p&gt;

&lt;p&gt;There are a number of different debugging tools available for JavaScript. Some popular debugging tools include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Chrome DevTools:&lt;/strong&gt;  Chrome DevTools is a powerful debugging tool that is built into the Chrome web browser. Chrome DevTools allows you to inspect the DOM, the JavaScript code, and the network traffic for a web page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://developer.chrome.com/docs/devtools/open/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GyawFFVp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/http://t0.gstatic.com/images%3Fq%3Dtbn:ANd9GcR5QU_XnwuefOWIb2LT7JffqkV_tSz-YrEFEv4049e3R8B3b98%26s" alt="Chrome DevTools in Google Chrome" width="293" height="172"&gt;Opens in a new window&lt;/a&gt;&lt;a href="https://developer.chrome.com/docs/devtools/open/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H8vUH8YF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://encrypted-tbn2.gstatic.com/favicon-tbn%3Fq%3Dtbn:ANd9GcTyQ6ZfcGYnIUHVsUqEJ0fvn0_l90Mn-wzbcA55sBR0uEp-oY0YTZSWHZauWg0MJz06e7nlyXhIZ6YLpIsIlBXm_REA-trHcAmi7_qebkY" alt="" width="16" height="16"&gt;Chrome Developers&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Chrome DevTools in Google Chrome&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Node Inspector:&lt;/strong&gt;  Node Inspector is a debugging tool for Node.js applications. Node Inspector allows you to inspect the JavaScript code, the environment variables, and the system logs for a Node.js application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/node-js-debugging/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4j9CrMW4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/http://t0.gstatic.com/images%3Fq%3Dtbn:ANd9GcQq1q-i31BOmVCheCnlpiZG6r7_yiXoIXoRO-mNCFV9QHov2EM%26s" alt="Node Inspector in Node.js" width="299" height="168"&gt;Opens in a new window&lt;/a&gt;&lt;a href="https://www.geeksforgeeks.org/node-js-debugging/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dSxc42fM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://encrypted-tbn1.gstatic.com/favicon-tbn%3Fq%3Dtbn:ANd9GcRfake8ZLwBRPlm00ybDFsx8Q6-gGjWz2RT8rYcf1d9dpDVQQlCIdQNuxUNGiczpg2b2VV4nMLO5MpFcuxiqctZPAgsnlC0_DlEUkwozrQV" alt="" width="16" height="16"&gt;GeeksforGeeks&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Node Inspector in Node.js&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;WebStorm:&lt;/strong&gt;  WebStorm is a commercial IDE for JavaScript development. WebStorm includes a powerful debugger that allows you to inspect the JavaScript code, the DOM, and the network traffic for a web page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://lp.jetbrains.com/webstorm-ide/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tVB3ynfh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/http://t0.gstatic.com/images%3Fq%3Dtbn:ANd9GcQYU_hZQ_ISDG5fkQR6Z_Pt8E833r9kvR2CbxFm_MpieYUi7UNQ%26s" alt="WebStorm IDE" width="294" height="171"&gt;Opens in a new window&lt;/a&gt;&lt;a href="https://lp.jetbrains.com/webstorm-ide/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AMP2FHvL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://encrypted-tbn2.gstatic.com/favicon-tbn%3Fq%3Dtbn:ANd9GcQ6YH-pMoyxe8NMmL9uIBSIDOMtmHnuInaVgRdyuEbw6kP5Xi-w_N6mpbX7upIdqBmzwGJsbKHJt_FAaZHVNvHiNknnAFw7nq779A" alt="" width="16" height="16"&gt;JetBrains&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;WebStorm IDE&lt;/p&gt;

&lt;p&gt;No matter what debugging tool you choose, the most important thing is to be patient and persistent. Debugging can be a time-consuming process, but it is essential for finding and fixing errors in your code.&lt;/p&gt;

&lt;p&gt;Here are some additional tips for debugging JavaScript code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Start by isolating the problem.&lt;/strong&gt;  Try to narrow down the problem to a specific part of your code. This can be done by using breakpoints and the  &lt;code&gt;console.log()&lt;/code&gt;  function.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Use the debugger's features to inspect the code.&lt;/strong&gt;  The debugger's features can be used to inspect the values of variables, the structure of the code, and the execution of the code.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Be patient and persistent.&lt;/strong&gt;  Debugging can be a time-consuming process, but it is essential for finding and fixing errors in your code.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Technical Paper on HTML/CSS</title>
      <dc:creator>Atchukola Naresh</dc:creator>
      <pubDate>Wed, 24 May 2023 12:48:25 +0000</pubDate>
      <link>https://dev.to/god7780/technical-paper-on-htmlcss-48fo</link>
      <guid>https://dev.to/god7780/technical-paper-on-htmlcss-48fo</guid>
      <description>&lt;h2&gt;
  
  
  CSS Box Model:
&lt;/h2&gt;

&lt;p&gt;The CSS box model is a way of representing HTML elements in CSS. It consists of four parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Content&lt;/strong&gt; - This is the actual content of the element, such as text or images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Padding&lt;/strong&gt; - This is the space between the content and the border.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Border&lt;/strong&gt; - This is the line that surrounds the content and padding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Margin&lt;/strong&gt; - This is the space between the border and other elements on the page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following image shows the different parts of the box model:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---vH84e-x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/http://t0.gstatic.com/images%3Fq%3Dtbn:ANd9GcR8rHP8rchKSRNlU0ogs0VIIOqJZ3-6Q_yVszyoLLPj53vJh3oP%26s" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---vH84e-x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/http://t0.gstatic.com/images%3Fq%3Dtbn:ANd9GcR8rHP8rchKSRNlU0ogs0VIIOqJZ3-6Q_yVszyoLLPj53vJh3oP%26s" alt="CSS box model" width="271" height="186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The size of the box is determined by the sum of the widths and heights of the content, padding, border, and margin. For example, if the content is 100px wide, the padding is 20px, the border is 10px, and the margin is 10px, then the total width of the box will be 140px.&lt;/p&gt;

&lt;p&gt;The CSS box model can be used to control the appearance of HTML elements in a variety of ways. For example, you can use the &lt;code&gt;padding&lt;/code&gt; property to add space around the content, the &lt;code&gt;border&lt;/code&gt; property to add a border around the element, and the &lt;code&gt;margin&lt;/code&gt; property to add space between the element and other elements on the page.&lt;/p&gt;

&lt;p&gt;Here are some examples of how to use the CSS box model to style HTML elements:&lt;/p&gt;

&lt;p&gt;CSS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p {
  padding: 10px;
  border: 1px solid black;
  margin: 5px;
}

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

&lt;/div&gt;



&lt;p&gt;This code will add a 10px padding, a 1px solid black border, and a 5px margin to all paragraphs on the page.&lt;/p&gt;

&lt;p&gt;CSS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  padding: 10px;
  border: 1px solid black;
  margin: 5px;
  background-color: blue;
}

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

&lt;/div&gt;



&lt;p&gt;This code will add a 10px padding, a 1px solid black border, a 5px margin, and a blue background color to all div elements on the page.&lt;/p&gt;

&lt;p&gt;The CSS box model is a powerful tool that can be used to control the appearance of HTML elements in a variety of ways. By understanding the different parts of the box model and how to use the CSS properties that control them, you can create custom styles that will make your web pages look their best.&lt;/p&gt;

&lt;h1&gt;
  
  
  -   Inline versus Block Elements. Examples:
&lt;/h1&gt;

&lt;p&gt;some examples of inline and block elements in CSS:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inline Elements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;&amp;lt;em&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Block Elements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Inline elements are displayed inline with the surrounding text, while block elements start on a new line and take up the full width of their container.&lt;/p&gt;

&lt;p&gt;Here is an example of how inline and block elements are displayed:&lt;/p&gt;

&lt;p&gt;HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p&amp;gt;This is a paragraph.&amp;lt;/p&amp;gt;

&amp;lt;div&amp;gt;This is a div element.&amp;lt;/div&amp;gt;

&amp;lt;a href="#"&amp;gt;This is a link.&amp;lt;/a&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;The paragraph will be displayed on a new line, while the div element and the link will be displayed inline with the surrounding text.&lt;/p&gt;

&lt;p&gt;You can use the &lt;code&gt;display&lt;/code&gt; property to change the display type of an element. For example, the following code will change the display type of the div element to inline:&lt;/p&gt;

&lt;p&gt;CSS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  display: inline;
}

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

&lt;/div&gt;



&lt;p&gt;This will cause the div element to be displayed inline with the surrounding text, just like the link element.&lt;/p&gt;

&lt;p&gt;You can also use the &lt;code&gt;display&lt;/code&gt; property to create custom layouts. For example, the following code will create a two-column layout:&lt;/p&gt;

&lt;p&gt;CSS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  display: inline-block;
}

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

&lt;/div&gt;



&lt;p&gt;This will cause the div elements to be displayed side-by-side, with a small gap between them.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;display&lt;/code&gt; property is a powerful tool that can be used to control the layout of your web pages. By understanding the different display types and how to use them, you can create custom layouts that will make your pages look their best.&lt;/p&gt;

&lt;h1&gt;
  
  
  Positioning: Relative/Absolute:
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Static:&lt;/strong&gt;  The default value. Elements with static positioning are placed in the document flow according to their source order.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Relative:&lt;/strong&gt;  Elements with relative positioning are positioned relative to their original position in the document flow. This means that they can be moved around using the  &lt;code&gt;top&lt;/code&gt;,  &lt;code&gt;left&lt;/code&gt;,  &lt;code&gt;bottom&lt;/code&gt;, and  &lt;code&gt;right&lt;/code&gt;  properties.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Absolute:&lt;/strong&gt;  Elements with absolute positioning are positioned relative to the nearest positioned ancestor element. If there is no positioned ancestor element, then the element is positioned relative to the  &lt;code&gt;html&lt;/code&gt;  element. Absolute positioned elements are removed from the document flow, and they do not affect the layout of other elements on the page.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Fixed:&lt;/strong&gt;  Elements with fixed positioning are positioned relative to the viewport. This means that they stay in the same place on the page, even when the user scrolls. Fixed positioned elements are also removed from the document flow.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an example of how to use relative positioning to move an element 10 pixels to the right:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.my-element {
  position: relative;
  right: 10px;
}

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

&lt;/div&gt;



&lt;p&gt;Here is an example of how to use absolute positioning to position an element 10 pixels to the right of its nearest positioned ancestor:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.my-element {
  position: absolute;
  right: 10px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Common CSS structural classes:
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;:first-child&lt;/strong&gt;  - Selects the first child of its parent.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;:last-child&lt;/strong&gt;  - Selects the last child of its parent.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;:only-child&lt;/strong&gt;  - Selects an element that is the only child of its parent.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;:nth-child(n)&lt;/strong&gt;  - Selects every nth child of its parent. For example,  &lt;code&gt;:nth-child(2)&lt;/code&gt;  will select every second child.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;:nth-of-type(n)&lt;/strong&gt;  - Selects every nth element of a particular type within its parent. For example,  &lt;code&gt;:nth-of-type(2) div&lt;/code&gt;  will select every second div within its parent.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;:nth-last-child(n)&lt;/strong&gt;  - Selects every nth child of its parent, counting from the last child. For example,  &lt;code&gt;:nth-last-child(2)&lt;/code&gt;  will select every second child, starting from the last child.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;:nth-last-of-type(n)&lt;/strong&gt;  - Selects every nth element of a particular type within its parent, counting from the last child. For example,  &lt;code&gt;:nth-last-of-type(2) div&lt;/code&gt;  will select every second div, starting from the last div.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;:first-of-type&lt;/strong&gt;  - Selects the first element of a particular type within its parent. For example,  &lt;code&gt;:first-of-type div&lt;/code&gt;  will select the first div within its parent.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;:last-of-type&lt;/strong&gt;  - Selects the last element of a particular type within its parent. For example,  &lt;code&gt;:last-of-type div&lt;/code&gt;  will select the last div within its parent.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;:only-of-type&lt;/strong&gt;  - Selects an element that is the only element of a particular type within its parent. For example,  &lt;code&gt;:only-of-type div&lt;/code&gt;  will select a div if it is the only div within its parent.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Common CSS styling classes:
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;.active:&lt;/strong&gt;  This class is used to style the currently active element, such as a link or button.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;.error:&lt;/strong&gt;  This class is used to style elements that have errors, such as form fields with invalid input.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;.info:&lt;/strong&gt;  This class is used to style elements that contain informational content.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;.success:&lt;/strong&gt;  This class is used to style elements that have been successfully processed, such as form submissions.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;.warning:&lt;/strong&gt;  This class is used to style elements that contain warnings or cautions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are just a few examples of common CSS styling classes. There are many other possible classes that can be used to style different elements on a web page.&lt;/p&gt;

&lt;p&gt;Here are some examples of how these classes can be used:&lt;/p&gt;

&lt;p&gt;CSS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.active {
  color: red;
  font-weight: bold;
}

.error {
  background-color: red;
  color: white;
}

.info {
  background-color: lightblue;
  color: black;
}

.success {
  background-color: green;
  color: white;
}

.warning {
  background-color: yellow;
  color: black;
}

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

&lt;/div&gt;



&lt;p&gt;These styles can be applied to any element on a web page by adding the appropriate class to the element's HTML tag. For example, to style a link as active, you would add the &lt;code&gt;active&lt;/code&gt; class to the &lt;code&gt;a&lt;/code&gt; tag.&lt;/p&gt;

&lt;p&gt;HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;a href="#"&amp;gt;This is an active link&amp;lt;/a&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;The CSS styles would then be applied to this link, making it appear red and bold.&lt;/p&gt;

&lt;p&gt;By using CSS styling classes, you can easily style different elements on a web page. This makes it possible to create a consistent look and feel for your website.&lt;/p&gt;

&lt;h1&gt;
  
  
  CSS Specificity:
&lt;/h1&gt;

&lt;p&gt;CSS specificity is a way of determining which CSS rule will be applied to an element when there are multiple rules that could apply. The rule with the highest specificity will be applied.&lt;/p&gt;

&lt;p&gt;Specificity is calculated by counting the number of IDs, classes, and elements in the selector. The more of each type of selector, the higher the specificity.&lt;/p&gt;

&lt;p&gt;For example, the following selector has a specificity of &lt;code&gt;1000&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#myID.myClass

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

&lt;/div&gt;



&lt;p&gt;This is because it has one ID selector (&lt;code&gt;#myID&lt;/code&gt;) and one class selector (&lt;code&gt;.myClass&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;The following selector has a specificity of &lt;code&gt;10&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.myClass

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

&lt;/div&gt;



&lt;p&gt;This is because it has one class selector (&lt;code&gt;.myClass&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;The following selector has a specificity of &lt;code&gt;1&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div

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

&lt;/div&gt;



&lt;p&gt;This is because it has one element selector (&lt;code&gt;div&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;If there are two rules that could apply to an element, the rule with the higher specificity will be applied. For example, the following two rules could both apply to an element:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#myID.myClass {
  color: red;
}

.myClass {
  color: blue;
}

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

&lt;/div&gt;



&lt;p&gt;The first rule has a specificity of &lt;code&gt;1000&lt;/code&gt; and the second rule has a specificity of &lt;code&gt;10&lt;/code&gt;. Therefore, the first rule will be applied and the element will be red.&lt;/p&gt;

&lt;p&gt;You can use specificity to override other CSS rules. For example, if you want to make sure that an element always has a certain color, you can use a rule with a high specificity. For example, the following rule will always make the element red, no matter what other rules are applied:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#myID {
  color: red;
}

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

&lt;/div&gt;



&lt;p&gt;You can also use specificity to make sure that a rule only applies to a certain element or set of elements. For example, the following rule will only apply to the element with the ID &lt;code&gt;myID&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#myID {
  color: red;
}

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

&lt;/div&gt;



&lt;p&gt;Specificity can be a bit confusing at first, but it is a very powerful tool that can help you control how CSS rules are applied.&lt;/p&gt;

&lt;h1&gt;
  
  
  CSS Responsive Queries:
&lt;/h1&gt;

&lt;p&gt;CSS responsive queries are a way to control how CSS styles are applied to a web page based on the size of the screen. This allows you to create a website that looks good on all devices, from large desktop monitors to small mobile phones.&lt;/p&gt;

&lt;p&gt;To use CSS responsive queries, you need to use the &lt;code&gt;@media&lt;/code&gt; rule. The &lt;code&gt;@media&lt;/code&gt; rule allows you to specify a set of CSS rules that will only be applied if the screen meets certain criteria. For example, you could use the &lt;code&gt;@media&lt;/code&gt; rule to specify a different layout for a mobile phone than you would for a desktop computer.&lt;/p&gt;

&lt;p&gt;The syntax for the &lt;code&gt;@media&lt;/code&gt; rule is as follows:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@media media_query {
  /* CSS rules */
}

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;media_query&lt;/code&gt; is a string that specifies the criteria that the screen must meet in order for the CSS rules to be applied. For example, the following &lt;code&gt;media_query&lt;/code&gt; would specify that the CSS rules should only be applied if the screen is less than 600 pixels wide:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@media screen and (max-width: 600px) {
  /* CSS rules */
}

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

&lt;/div&gt;



&lt;p&gt;You can use a variety of media queries to specify different criteria. For example, you could use the &lt;code&gt;min-width&lt;/code&gt; media query to specify that the CSS rules should only be applied if the screen is at least a certain width. You could also use the &lt;code&gt;orientation&lt;/code&gt; media query to specify that the CSS rules should only be applied if the screen is in landscape or portrait mode.&lt;/p&gt;

&lt;p&gt;Once you have defined your &lt;code&gt;@media&lt;/code&gt; rule, you can then specify the CSS rules that you want to apply. These rules will only be applied if the screen meets the criteria that you specified in the &lt;code&gt;media_query&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example, the following code would specify that the &lt;code&gt;h1&lt;/code&gt; element should be displayed in a larger font size on mobile phones:&lt;/p&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@media screen and (max-width: 600px) {
  h1 {
    font-size: 2em;
  }
}

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

&lt;/div&gt;



&lt;p&gt;CSS responsive queries are a powerful tool that can help you create a website that looks good on all devices. By using CSS responsive queries, you can ensure that your website is accessible to everyone, regardless of the device they are using.&lt;/p&gt;

&lt;h1&gt;
  
  
  Flexbox/Grid:
&lt;/h1&gt;

&lt;p&gt;Flexbox and Grid are two different CSS layout models that can be used to create complex and responsive layouts.&lt;/p&gt;

&lt;p&gt;Flexbox is a newer layout model that is designed for flexibility and responsiveness. It is based on the concept of a flex container, which can contain any number of flex items. The flex items can be arranged in a single row or column, or they can be arranged in a grid.&lt;/p&gt;

&lt;p&gt;Grid is an older layout model that is designed for more complex layouts. It is based on the concept of a grid container, which can contain any number of grid items. The grid items can be arranged in a grid of any size, and they can be positioned anywhere in the grid.&lt;/p&gt;

&lt;p&gt;Both Flexbox and Grid are powerful layout models that can be used to create complex and responsive layouts. However, they have different strengths and weaknesses.&lt;/p&gt;

&lt;p&gt;Flexbox is a good choice for layouts that need to be flexible and responsive. It is easy to learn and use, and it can be used to create a wide variety of layouts.&lt;/p&gt;

&lt;p&gt;Grid is a good choice for layouts that need to be more complex. It is more powerful than Flexbox, and it can be used to create layouts that are not possible with Flexbox.&lt;/p&gt;

&lt;p&gt;Ultimately, the best choice for you will depend on the specific needs of your layout. If you need a flexible and responsive layout, then Flexbox is a good choice. If you need a more complex layout, then Grid is a good choice.&lt;/p&gt;

&lt;p&gt;Here are some examples of how Flexbox and Grid can be used to create layouts:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flexbox&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A simple layout with a header, body, and footer:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
  &amp;lt;header&amp;gt;
    &amp;lt;h1&amp;gt;This is the header&amp;lt;/h1&amp;gt;
  &amp;lt;/header&amp;gt;
  &amp;lt;main&amp;gt;
    &amp;lt;p&amp;gt;This is the main content&amp;lt;/p&amp;gt;
  &amp;lt;/main&amp;gt;
  &amp;lt;footer&amp;gt;
    &amp;lt;p&amp;gt;This is the footer&amp;lt;/p&amp;gt;
  &amp;lt;/footer&amp;gt;
&amp;lt;/div&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  A layout with a sidebar and main content area:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
  &amp;lt;aside class="sidebar"&amp;gt;
    &amp;lt;ul&amp;gt;
      &amp;lt;li&amp;gt;&amp;lt;a href="#"&amp;gt;This is a link&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
      &amp;lt;li&amp;gt;&amp;lt;a href="#"&amp;gt;This is another link&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
      &amp;lt;li&amp;gt;&amp;lt;a href="#"&amp;gt;This is one more link&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
    &amp;lt;/ul&amp;gt;
  &amp;lt;/aside&amp;gt;
  &amp;lt;main&amp;gt;
    &amp;lt;p&amp;gt;This is the main content&amp;lt;/p&amp;gt;
  &amp;lt;/main&amp;gt;
&amp;lt;/div&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Grid&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A simple layout with a grid of images:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
  &amp;lt;div class="row"&amp;gt;
    &amp;lt;div class="col-md-4"&amp;gt;
      &amp;lt;img src="image1.jpg" alt="Image 1"&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="col-md-4"&amp;gt;
      &amp;lt;img src="image2.jpg" alt="Image 2"&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="col-md-4"&amp;gt;
      &amp;lt;img src="image3.jpg" alt="Image 3"&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  A layout with a grid of images and text:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
  &amp;lt;div class="row"&amp;gt;
    &amp;lt;div class="col-md-4"&amp;gt;
      &amp;lt;img src="image1.jpg" alt="Image 1"&amp;gt;
      &amp;lt;h2&amp;gt;This is the title&amp;lt;/h2&amp;gt;
      &amp;lt;p&amp;gt;This is the text&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="col-md-4"&amp;gt;
      &amp;lt;img src="image2.jpg" alt="Image 2"&amp;gt;
      &amp;lt;h2&amp;gt;This is another title&amp;lt;/h2&amp;gt;
      &amp;lt;p&amp;gt;This is another text&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="col-md-4"&amp;gt;
      &amp;lt;img src="image3.jpg" alt="Image 3"&amp;gt;
      &amp;lt;h2&amp;gt;This is one more title&amp;lt;/h2&amp;gt;
      &amp;lt;p&amp;gt;This is one more text&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;As you can see, both Flexbox and Grid can be used to create a wide variety of layouts. The best choice for you will depend on the specific needs of your layout.&lt;/p&gt;

&lt;h1&gt;
  
  
  Common header meta tags:
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Title:&lt;/strong&gt;  The title meta tag is used to specify the title of the page. This title is displayed in the browser's title bar and in search engine results pages (SERPs).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="title" content="This is the title of the page"&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Description:&lt;/strong&gt;  The description meta tag is used to provide a brief description of the page. This description is displayed in SERPs, and it can help users decide whether or not to click on your link.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="description" content="This is a brief description of the page"&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Keywords:&lt;/strong&gt;  The keywords meta tag is used to specify the keywords that are relevant to the page. This information can be used by search engines to index your page and to rank it in search results.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="keywords" content="keyword1, keyword2, keyword3"&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Robots:&lt;/strong&gt;  The robots meta tag is used to control how search engines crawl and index your page. For example, you can use the robots meta tag to prevent search engines from crawling your sitemap or from indexing your contact page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="robots" content="index, follow"&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Viewport:&lt;/strong&gt;  The viewport meta tag is used to control the initial size of the browser window. This can be useful for mobile devices, where you may want to specify a smaller initial window size.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="viewport" content="width=device-width, initial-scale=1"&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Content-Type:&lt;/strong&gt;  The Content-Type meta tag is used to specify the MIME type of the page. This information is used by the browser to determine how to render the page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Refresh:&lt;/strong&gt;  The Refresh meta tag is used to automatically refresh the page after a specified amount of time. This can be useful for pages that display news or other time-sensitive information.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta http-equiv="refresh" content="30"&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Author:&lt;/strong&gt;  The Author meta tag is used to specify the author of the page. This information can be displayed in SERPs, and it can help users to identify the source of the information.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="author" content="John Doe"&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Copyright:&lt;/strong&gt;  The Copyright meta tag is used to specify the copyright information for the page. This information can be displayed in SERPs, and it can help users to understand the terms of use for the page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="copyright" content="Copyright 2023, John Doe"&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Noindex:&lt;/strong&gt;  The Noindex meta tag is used to prevent search engines from indexing the page. This can be useful for pages that are not intended to be indexed, such as login pages or private pages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="robots" content="noindex"&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Nofollow:&lt;/strong&gt;  The Nofollow meta tag is used to prevent search engines from following links on the page. This can be useful for pages that contain spammy or irrelevant links.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;a href="https://www.spammywebsite.com" rel="nofollow"&amp;gt;This is a spammy link&amp;lt;/a&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;These are just a few of the most common header meta tags. There are many other meta tags that can be used, and the specific meta tags that you use will depend on the needs of website.&lt;/p&gt;

&lt;h1&gt;
  
  
  Inheritence:
&lt;/h1&gt;

&lt;p&gt;Inheritance in CSS and HTML is the ability of an element to inherit properties from its parent element. This can be used to save time and effort when styling a web page, as you only need to specify the properties once on the parent element and they will be inherited by all child elements.&lt;/p&gt;

&lt;p&gt;To inherit a property in CSS, you use the &lt;code&gt;inherit&lt;/code&gt; keyword. For example, the following code will set the font size of all &lt;code&gt;p&lt;/code&gt; elements to 16px:&lt;/p&gt;

&lt;p&gt;CSS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p {
  font-size: 16px;
}

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

&lt;/div&gt;



&lt;p&gt;This will also set the font size of all child elements of &lt;code&gt;p&lt;/code&gt; elements, such as &lt;code&gt;span&lt;/code&gt; elements.&lt;/p&gt;

&lt;p&gt;In HTML, inheritance is used to determine the default values of attributes. For example, the &lt;code&gt;href&lt;/code&gt; attribute of the &lt;code&gt;a&lt;/code&gt; element has a default value of &lt;code&gt;#&lt;/code&gt;. This means that if you do not specify an &lt;code&gt;href&lt;/code&gt; attribute on an &lt;code&gt;a&lt;/code&gt; element, it will link to the current page.&lt;/p&gt;

&lt;p&gt;Inheritance can be a powerful tool when used correctly. However, it is important to understand how it works so that you can avoid unintended consequences. For example, if you set the &lt;code&gt;color&lt;/code&gt; property of a parent element to &lt;code&gt;red&lt;/code&gt;, all child elements will also be red, even if you have explicitly set the &lt;code&gt;color&lt;/code&gt; property of a child element to a different color.&lt;/p&gt;

&lt;p&gt;To avoid this, you can use the &lt;code&gt;!important&lt;/code&gt; keyword to override the inherited value of a property. For example, the following code will set the &lt;code&gt;color&lt;/code&gt; property of the &lt;code&gt;span&lt;/code&gt; element to &lt;code&gt;blue&lt;/code&gt;, even though the &lt;code&gt;color&lt;/code&gt; property of the &lt;code&gt;p&lt;/code&gt; element is set to &lt;code&gt;red&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;CSS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p {
  color: red;
}

span {
  color: blue !important;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>S.O.L.I.D Principles</title>
      <dc:creator>Atchukola Naresh</dc:creator>
      <pubDate>Mon, 15 May 2023 10:36:35 +0000</pubDate>
      <link>https://dev.to/god7780/solid-principles-i6m</link>
      <guid>https://dev.to/god7780/solid-principles-i6m</guid>
      <description>&lt;h1&gt;
  
  
  SOLID Principles
&lt;/h1&gt;

&lt;p&gt;These are the oldest principles but we are still using these priciples due to maintains's&lt;br&gt;
OO systems improve reusabulity and easy testing.&lt;/p&gt;
&lt;h3&gt;
  
  
  S.O.L.I.D
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;SRP - Single responsibility principle &lt;/li&gt;
&lt;li&gt;DIP - Dependency inversion principle &lt;/li&gt;
&lt;li&gt;OCP - Open/closed principle &lt;/li&gt;
&lt;li&gt;LSP - Liskov substitution principle&lt;/li&gt;
&lt;li&gt;ISP - Interface segregation principle&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  SRP - Single responsibility principle:
&lt;/h1&gt;

&lt;p&gt;A class should have only one responsibilty all the methods should be associated with the &lt;br&gt;
that responsibility.&lt;/p&gt;

&lt;p&gt;example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;recipient&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
         &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subject&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sender&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;recipient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;recipien&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EmailSender&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;send_email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# Code to send the email using the SMTP server
&lt;/span&gt;        &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EmailSaver&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;save_email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# Code to save the email to a database
&lt;/span&gt;        &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have separate classes for each responsibility: &lt;code&gt;Email&lt;/code&gt; for storing email data, &lt;code&gt;EmailSender&lt;/code&gt; for sending emails, and &lt;code&gt;EmailSaver&lt;/code&gt; for saving emails to a database. Each class has a single responsibility, making the system easier to understand, modify, and maintain.&lt;/p&gt;

&lt;h3&gt;
  
  
  OCP - Open/closed principle  :
&lt;/h3&gt;

&lt;p&gt;The Open-Closed Principle (OCP) is a fundamental principle in object-oriented programming that states that software entities (classes, modules, functions, etc.) should be open for extension but closed for modification. In other words, the behavior of a system should be extendable without modifying its existing code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;abc&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ABC&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;abstractmethod&lt;/span&gt;

&lt;span class="c1"&gt;# Abstract class representing a shape
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ABC&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;abstractmethod&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;

&lt;span class="c1"&gt;# Concrete implementation of a Rectangle shape
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Rectangle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;

&lt;span class="c1"&gt;# Concrete implementation of a Circle shape
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;

&lt;span class="c1"&gt;# Function that calculates the sum of areas for multiple shapes
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_total_area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;shapes&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;total_area&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;shape&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;shapes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;total_area&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;shape&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;area&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;total_area&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;, if we want to add a &lt;code&gt;Triangle&lt;/code&gt; shape, we can create a new class &lt;code&gt;Triangle&lt;/code&gt; that inherits from &lt;code&gt;Shape&lt;/code&gt; and provides its own implementation of the &lt;code&gt;area()&lt;/code&gt; method. We can then pass an instance of &lt;code&gt;Triangle&lt;/code&gt; to the &lt;code&gt;calculate_total_area()&lt;/code&gt; function, and it will work seamlessly without modifying the existing code.&lt;/p&gt;

&lt;h1&gt;
  
  
  LSP - Liskov substitution principle:
&lt;/h1&gt;

&lt;p&gt;The Liskov Substitution Principle (LSP) is a principle in object-oriented programming that states that objects of a superclass should be replaceable with objects of its subclasses without affecting the correctness of the program. In other words, if a program is designed to work with a certain type of object, it should also work correctly with any subtype of that object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;make_sound&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Animal&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;make_sound&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Woof!"&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Animal&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;make_sound&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Meow!"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;animal_sounds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;animals&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;animal&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;animals&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;animal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;make_sound&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;animal_sounds()&lt;/code&gt; function demonstrates the Liskov Substitution Principle. It takes a list of &lt;code&gt;Animal&lt;/code&gt; objects and calls the &lt;code&gt;make_sound()&lt;/code&gt; method on each object. By designing the program to work with the &lt;code&gt;Animal&lt;/code&gt; superclass, it can also work correctly with any subtype of &lt;code&gt;Animal&lt;/code&gt;, such as &lt;code&gt;Dog&lt;/code&gt; or &lt;code&gt;Cat&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;animals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;Cat&lt;/span&gt;&lt;span class="p"&gt;()]&lt;/span&gt;

&lt;span class="n"&gt;animal_sounds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;animals&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;animal_sounds()&lt;/code&gt; function doesn't need to know the exact type of each object in the list. It treats them all as &lt;code&gt;Animal&lt;/code&gt; objects and calls the &lt;code&gt;make_sound()&lt;/code&gt; method, which is overridden in the subclasses. As a result, it will print "Woof!" and "Meow!" without any issues.&lt;/p&gt;

&lt;h3&gt;
  
  
  ISP - Interface segregation principle:
&lt;/h3&gt;

&lt;p&gt;The Interface Segregation Principle (ISP) is a principle in object-oriented programming that states that clients should not be forced to depend on interfaces they do not use. It suggests that classes should have narrowly focused interfaces, tailored to the specific needs of the clients that use them, rather than having large, bloated interfaces that encompass more functionality than necessary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from abc import ABC, abstractmethod

# Interface for a document
class Document(ABC):
    @abstractmethod
    def open(self):
        pass

    @abstractmethod
    def close(self):
        pass

# Interface for a printable document
class Printable(ABC):
    @abstractmethod
    def print_document(self):
        pass

# Interface for a scannable document
class Scannable(ABC):
    @abstractmethod
    def scan_document(self):
        pass

# Implementation of a Word document
class WordDocument(Document, Printable):
    def open(self):
        print("Opening Word document")

    def close(self):
        print("Closing Word document")

    def print_document(self):
        print("Printing Word document")

# Implementation of a PDF document
class PdfDocument(Document, Printable, Scannable):
    def open(self):
        print("Opening PDF document")

    def close(self):
        print("Closing PDF document")

    def print_document(self):
        print("Printing PDF document")

    def scan_document(self):
        print("Scanning PDF document")

# Client code that only depends on the required interfaces
def print_document(printable):
    printable.print_document()

def scan_document(scannable):
    scannable.scan_document()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The client code demonstrates the usage of the specific interfaces. The &lt;code&gt;print_document()&lt;/code&gt; function only depends on the &lt;code&gt;Printable&lt;/code&gt; interface, allowing it to print any document that implements that interface. Similarly, the &lt;code&gt;scan_document()&lt;/code&gt; function only depends on the &lt;code&gt;Scannable&lt;/code&gt; interface, allowing it to scan any document that implements that interface.&lt;/p&gt;

&lt;h3&gt;
  
  
  DIP - Dependency inversion principle :
&lt;/h3&gt;

&lt;p&gt;The Dependency Inversion Principle (DIP) is a principle in object-oriented programming that states that high-level modules should not depend on low-level modules. Instead, both should depend on abstractions. It suggests that the dependencies between modules should be based on abstractions rather than concrete implementations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from abc import ABC, abstractmethod

# Abstract class representing a notifier
class Notifier(ABC):
    @abstractmethod
    def send_notification(self, message):
        pass

# High-level module that depends on the Notifier abstraction
class NotificationService:
    def __init__(self, notifier):
        self.notifier = notifier

    def send_notification(self, message):
        self.notifier.send_notification(message)

# Low-level module that implements the Notifier abstraction
class EmailNotifier(Notifier):
    def send_notification(self, message):
        print(f"Sending email notification: {message}")

# Low-level module that implements the Notifier abstraction
class SMSNotifier(Notifier):
    def send_notification(self, message):
        print(f"Sending SMS notification: {message}")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By having the &lt;code&gt;NotificationService&lt;/code&gt; depend on the &lt;code&gt;Notifier&lt;/code&gt; abstraction rather than concrete implementations, we adhere to the Dependency Inversion Principle. The &lt;code&gt;NotificationService&lt;/code&gt; is not tightly coupled to specific notifiers (e.g., &lt;code&gt;EmailNotifier&lt;/code&gt; or &lt;code&gt;SMSNotifier&lt;/code&gt;), but instead depends on the abstraction provided by the &lt;code&gt;Notifier&lt;/code&gt; class. This allows for flexibility and extensibility in the system. We can introduce new notifiers by creating classes that implement the &lt;code&gt;Notifier&lt;/code&gt; interface, and the &lt;code&gt;NotificationService&lt;/code&gt; will work with them without any modifications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;email_notifier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;EmailNotifier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;sms_notifier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;SMSNotifier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;notification_service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;NotificationService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;email_notifier&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;notification_service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_notification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, this is an email notification"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;notification_service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;NotificationService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sms_notifier&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;notification_service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_notification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, this is an SMS notification"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>DBMS Technical Paper</title>
      <dc:creator>Atchukola Naresh</dc:creator>
      <pubDate>Fri, 12 May 2023 13:48:00 +0000</pubDate>
      <link>https://dev.to/god7780/dbms-technical-paper-51nn</link>
      <guid>https://dev.to/god7780/dbms-technical-paper-51nn</guid>
      <description>&lt;h1&gt;
  
  
  ACID Properties:
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Introduction to ACID Properties in DBMS
&lt;/h2&gt;

&lt;p&gt;ACID Properties in DBMS ensure consistency and reliability in transactions. For example, when two users try to book the same train ticket, the user who clicks the 'Book Now' button first is given preference. Without ACID Properties, both users could end up with a confirmed ticket, causing problems. ACID Properties prevent errors and maintain consistency, which is crucial when multiple users are trying to book/purchase the same thing&lt;/p&gt;

&lt;h2&gt;
  
  
  What are ACID Properties in DBMS?
&lt;/h2&gt;

&lt;p&gt;ACID properties are a set of properties that guarantee reliable processing of transactions in a database management system (DBMS). Transactions are a sequence of database operations that are executed as a single unit of work, and the ACID properties ensure that transactions are processed reliably and consistently in a DBMS.&lt;/p&gt;

&lt;p&gt;The Atomicity property ensures that a transaction is either executed completely or not at all. The Consistency property ensures that the database remains in a consistent state before and after a transaction. The Isolation property ensures that multiple transactions can run concurrently without interfering with each other. The Durability property ensures that the results of a committed transaction are permanent and cannot be lost due to system failure.&lt;/p&gt;

&lt;p&gt;Together, these properties ensure that transactions are processed reliably and consistently in a DBMS, which is essential for the integrity and accuracy of data in a database.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Atomicity in DBMS
&lt;/h3&gt;

&lt;p&gt;The term atomicity is the ACID Property in DBMS that refers to the fact that the data is kept atomic. It means that if any operation on the data is conducted, it should either be executed completely or not at all. It also implies that the operation should not be interrupted or just half completed. When performing operations on a transaction, the operation should be completed totally rather than partially. If any of the operations aren’t completed fully, the transaction gets aborted.&lt;br&gt;&lt;br&gt;
Sometimes, a current operation will be running and then, an operation with a higher priority enters. This discontinues the current operation and the current operation will be aborted.&lt;/p&gt;

&lt;p&gt;In the example above, if we consider the case that both users get notified that the seat is booked and neither of them is allowed to be seated because only one seat is available on the train, that is a half-fulfilled transaction. The transaction would be complete if they were able to be seated as well. Instead, according to atomicity, the person who clicks the button first books the seat and gets the notification of having purchased a ticket, and the seats left are updated. The second person’s transaction is rolled back and they are notified that no more seats are available. Let us consider an easier example where one person is trying to book a ticket. They were able to select their seat and reach the payment gateway. But, due to bank server issues, the payment could not go through. Does this mean that their booked seat will be reserved for them?&lt;br&gt;&lt;br&gt;
No. This is because one full transaction means reserving your seat and paying for it as well. If any of the steps fail, the operation will be aborted and you will be brought back to the initial state.&lt;/p&gt;

&lt;p&gt;Atomicity in DBMS is often referred to as the ‘all or nothing’ rule.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Consistency in DBMS
&lt;/h3&gt;

&lt;p&gt;This ACID Property will verify the total sum of seats left in the train+sum of seats booked by users=total the number of seats present in the train. After each transaction, consistency is checked to ensure nothing has gone wrong.&lt;/p&gt;

&lt;p&gt;Let us consider an example where one person is trying to book a ticket. They are able to reserve their seat but their payment hasn’t gone through due to bank issues. In this case, their transaction is rolled back. But just doing that isn’t sufficient. The number of available seats must also be updated. Otherwise, if it isn’t updated, there will be an inconsistency where the seat given up by the person is not accounted for. Hence, the total sum of seats left in the train + the sum of seats booked by users would not be equal to the total number of seats present in the train if not for consistency.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Isolation in DBMS
&lt;/h3&gt;

&lt;p&gt;Isolation is defined as a state of separation. Isolation is an ACID Property in DBMS where no data from one database should impact the other and where many transactions can take place at the same time. In other words, when the operation on the first state of the database is finished, the process on the second state of the database should begin. It indicates that if two actions are conducted on two different databases, the value of one database may not be affected by the value of the other. When two or more transactions occur at the same time in the case of transactions, consistency should be maintained. Any modifications made in one transaction will not be visible to other transactions until the change is committed to the memory.&lt;/p&gt;

&lt;p&gt;Let us use our example of 2 people trying to book the same seat to understand this ACID Property. Two transactions are happening at the same item on the same database, but in isolation. To ensure that one transaction doesn’t affect the other, they are serialized by the system. This is done so as to maintain the data in a consistent state. Let us consider that the two people that click ‘Book Now’, do so with a gap of a few seconds. In that case, the first person’s transaction goes through and he/she receives their ticket as well. The second person will not know of the same until the first person’s transaction is committed to memory. When the second person clicks on ‘Book Now’ and is redirected to the payment gateway, since the first person’s seat has already been booked, it will show an error notifying the user that no seats are left on the train.&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Durability in DBMS
&lt;/h3&gt;

&lt;p&gt;The ACID Property durability in DBMS refers to the fact that if an operation is completed successfully, the database remains permanent in the disk. The database’s durability should be such that even if the system fails or crashes, the database will survive. However, if the database is lost, the recovery manager is responsible for guaranteeing the database’s long-term viability. Every time we make a change, we must use the COMMIT command to commit the values.&lt;/p&gt;

&lt;p&gt;Imagine a system failure or crash occurs in the railway management system and all the trains that everyone had booked have been removed from the system. That means millions of users would have paid the money for their seats but will not be able to board the train as all the details have been destroyed. This could lead to huge losses for the company as users would lose trust in them. In addition, it would create a lot of panics as these trains would be needed for important reasons as well.&lt;/p&gt;
&lt;h1&gt;
  
  
  CAP Theorem:
&lt;/h1&gt;

&lt;p&gt;CAP  Theorem is very imorantant while working with distributed environment.&lt;/p&gt;
&lt;h3&gt;
  
  
  Distributed enviroment:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;a collection of independent components located on different machines that share messages with each other in order to achieve common goals&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The CAP theorem&lt;/strong&gt;, originally introduced as the CAP principle, can be used to explain some of the competing requirements in a distributed system with replication. It is a tool used to make system designers aware of the trade-offs while designing networked shared-data systems.&lt;/p&gt;

&lt;p&gt;The three letters in CAP refer to three desirable properties of distributed systems with replicated data:  &lt;strong&gt;consistency&lt;/strong&gt;  (among replicated copies),  &lt;strong&gt;availability&lt;/strong&gt;  (of the system for read and write operations) and &lt;strong&gt;partition tolerance&lt;/strong&gt;  (in the face of the nodes in the system being partitioned by a network fault).&lt;/p&gt;

&lt;p&gt;The CAP theorem states that it is not possible to guarantee all three of the desirable properties – consistency, availability, and partition tolerance at the same time in a distributed system with data replication.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency –&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Consistency means that the nodes will have the same copies of a replicated data item visible for various transactions. A guarantee that every node in a distributed cluster returns the same, most recent and a successful write. Consistency refers to every client having the same view of the data. There are various types of consistency models. Consistency in CAP refers to sequential consistency, a very strong form of consistency.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Availability –&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Availability means that each read or write request for a data item will either be processed successfully or will receive a message that the operation cannot be completed. Every non-failing node returns a response for all the read and write requests in a reasonable amount of time. The key word here is “every”. In simple terms, every node (on either side of a network partition) must be able to respond in a reasonable amount of time.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Partition Tolerance –&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Partition tolerance means that the system can continue operating even if the network connecting the nodes has a fault that results in two or more partitions, where the nodes in each partition can only communicate among each other. That means, the system continues to function and upholds its consistency guarantees in spite of network partitions. Network partitions are a fact of life. Distributed systems guaranteeing partition tolerance can gracefully recover from partitions once the partition heals.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  JOINS :
&lt;/h1&gt;
&lt;h2&gt;
  
  
  What are JOINS in SQL?
&lt;/h2&gt;

&lt;p&gt;SQL Joins are mostly used when a user is trying to extricate data from multiple tables (which have one-to-many or many-to-many relationships with each other) at one time. The join keyword merges two or more tables and creates a temporary image of the merged table. Then according to the conditions provided, it extracts the required data from the image table, and once data is fetched, the temporary image of the merged tables is dumped.&lt;/p&gt;
&lt;h2&gt;
  
  
  Types of JOINS in SQL
&lt;/h2&gt;
&lt;h3&gt;
  
  
  INNER JOIN in SQL
&lt;/h3&gt;

&lt;p&gt;SQL Inner Join or Equi Join is the simplest join where all rows from the intended tables are cached together if they meet the stated condition. Two or more tables are required for this join. Inner Join can be used with various SQL conditional statements like WHERE, GROUP BY,  &lt;a href="https://www.scaler.com/topics/sql/order-by-clause-in-sql/"&gt;ORDER BY&lt;/a&gt;, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xmhl9X3O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/joins-in-sql-4.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xmhl9X3O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/joins-in-sql-4.webp" alt="SQL inner join" width="800" height="644"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;General Syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; 
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;INNER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; 
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;We can alternately use just the “JOIN” keyword instead of “INNER JOIN”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8aG_E3Hj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/joins-in-sql-5.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8aG_E3Hj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/joins-in-sql-5.webp" alt="Equi Join in SQL" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Special Case of INNER JOIN: NATURAL JOIN
&lt;/h3&gt;

&lt;p&gt;SQL Natural Join is a type of Inner join based on the condition that columns having the same name and datatype are present in both the tables to be joined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;General Syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; 
&lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;NATURAL&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  OUTER JOINS in SQL
&lt;/h3&gt;

&lt;p&gt;SQL Outer joins give both matched and unmatched rows of data depending on the type of outer joins. These types are outer joins are sub-divided into the following types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Left Outer Join&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Right Outer Join&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Full Outer Join&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1. LEFT OUTER JOIN
&lt;/h3&gt;

&lt;p&gt;In this join, a.k.a.  &lt;a href="https://www.scaler.com/topics/left-join-in-sql/"&gt;SQL Left Join&lt;/a&gt;, all the rows of the left-hand table, regardless of following the stated conditions are added to the output table. At the same time, only matching rows of the right-hand table are added.&lt;/p&gt;

&lt;p&gt;Rows belonging to the left-hand table and not having values from the right-hand table are presented as NULL values in the resulting table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---Ud48uAi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/joins-in-sql-7.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---Ud48uAi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/joins-in-sql-7.webp" alt="Left Outer Join" width="800" height="632"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;General Syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;table1&lt;/span&gt; &lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;OUTER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;table2&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;table1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;table2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3CHFtPLT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/joins-in-sql-8.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3CHFtPLT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/joins-in-sql-8.webp" alt="Left Outer Join in SQL" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. RIGHT OUTER JOIN
&lt;/h3&gt;

&lt;p&gt;Similar to the left outer join, in the case of the Right Outer Join, a.k.a. SQL Right Join, all the rows on the right-hand table, regardless of following the stated conditions, are added to the output table. At the same time, only matching rows of the left-hand table are added.&lt;/p&gt;

&lt;p&gt;Rows belonging to the right-hand table and not having values from the left-hand table are presented as  &lt;a href="https://www.scaler.com/topics/sql/null-value-in-sql/"&gt;NULL values&lt;/a&gt;  in the resulting table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Szudk_WH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/joins-in-sql-9.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Szudk_WH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/joins-in-sql-9.webp" alt="Right Outer Join" width="800" height="641"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;General Syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;table1&lt;/span&gt; &lt;span class="k"&gt;RIGHT&lt;/span&gt; &lt;span class="k"&gt;OUTER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;table2&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;table1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;table2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qMWi7JOe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/joins-in-sql-10.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qMWi7JOe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/joins-in-sql-10.webp" alt="Right Outer Join in SQL" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. FULL OUTER JOIN
&lt;/h3&gt;

&lt;p&gt;The full outer join (a.k.a. SQL Full Join) first adds all the rows matching the stated condition in the query and then adds the remaining unmatched rows from both tables. We need two or more tables for the join.&lt;/p&gt;

&lt;p&gt;After the matched rows are added to the output table, the unmatched rows of the left-hand table are added with subsequent NULL values, and then unmatched rows of the right-hand table are added with subsequent NULL values.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8fHaYjgt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.scaler.com/topics/media/Full-Outer-Join-1024x1024.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8fHaYjgt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.scaler.com/topics/media/Full-Outer-Join-1024x1024.jpeg" alt="Full Outer Join" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;General Syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;table1&lt;/span&gt; &lt;span class="k"&gt;FULL&lt;/span&gt; &lt;span class="k"&gt;OUTER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;table2&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;table1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;table2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HSBp7Ekt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.scaler.com/topics/media/Full-Outer-Join-in-SQL-1024x742.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HSBp7Ekt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.scaler.com/topics/media/Full-Outer-Join-in-SQL-1024x742.jpeg" alt="Full Outer Join in SQL" width="800" height="580"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  -   Aggregations, Filters in queries:
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Aggregate functions&lt;/strong&gt; in SQL are used to perform operations on multiple rows of a table and return a single value. A single function can be used to compute multiple values and return the required result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Aggregate Functions in SQL
&lt;/h2&gt;

&lt;p&gt;Aggregate functions in SQL can be of the following types as shown in the figure. We will be understanding the working of these functions one by one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--arDnF7Fb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler-topics-articles-md.s3.us-west-2.amazonaws.com/sql-aggregate-function.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--arDnF7Fb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler-topics-articles-md.s3.us-west-2.amazonaws.com/sql-aggregate-function.webp" alt="SQL Aggregate Function" width="800" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. COUNT() Function
&lt;/h3&gt;

&lt;p&gt;The  COUNT()  aggregate function returns the total number of rows from a database table that matches the defined criteria in the SQL query.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;COLUMN_NAME&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;COUNT(*)  returns the total number of rows in a given table.  COUNT(COULUMN_NAME)  returns the total number of non-null values present in the column which is passed as an argument in the function.&lt;/p&gt;

&lt;p&gt;Let’s take a look at a few examples to understand the function better.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Suppose you want to know the total number of employees working in the organization. You can do so by the below-given query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;EMP_DATA&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;As  COUNT(&lt;em&gt;)  returns the total number of rows and the table named  EMP_DATA  provided above consists of 10 rows, so the  COUNT(&lt;/em&gt;)  function returns 10. The output is printed as shown below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. SUM() Function
&lt;/h3&gt;

&lt;p&gt;The  SUM()  function takes the name of the column as an argument and returns the sum of all the non NULL values in that column. It works only on numeric fields(i.e the columns contain only numeric values). When applied to columns containing both non-numeric(ex - strings) and numeric values, only numeric values are considered. If no numeric values are present, the function returns 0.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The function name is  SUM()  and the name of the column to be considered is passed as an argument to the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;COLUMN_NAME&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  3.AVG() Function
&lt;/h3&gt;

&lt;p&gt;The  AVG()  aggregate function uses the name of the column as an argument and returns the average of all the non NULL values in that column. It works only on numeric fields(i.e the columns contain only numeric values).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;  When applied to columns containing both non-numeric (ex - strings) and numeric values, only numeric values are considered. If no numeric values are present, the function returns 0.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The function name is  AVG()  and the name of the column to be considered is passed as an argument to the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;COLUMN_NAME&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. MIN() Function
&lt;/h3&gt;

&lt;p&gt;The  MIN()  function takes the name of the column as an argument and returns the minimum value present in the column.  MIN()  returns NULL when no row is selected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The function name is  MIN()  and the name of the column to be considered is passed as an argument to the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;MIN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;COLUMN_NAME&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;To understand this better, let’s take a look at some examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Suppose you want to find out what is the minimum salary that is provided by the organization. The  MIN()  function can be used here with the column name as an argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;MIN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;EMP_DATA&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. MAX() Function
&lt;/h3&gt;

&lt;p&gt;The  MAX()  function takes the name of the column as an argument and returns the maximum value present in the column.  MAX()  returns NULL when no row is selected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The function name is  MAX()  and the name of the column to be considered is passed as an argument to the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;MAX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;COLUMN_NAME&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  FILTER CLAUSE
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The filter clause is another tool for filtering in SQL.&lt;/strong&gt;  The filter clause is used to, as the name suggests, filter the input data to an aggregation function. They differ from the WHERE clause because they are more flexible than the WHERE clause. Only one WHERE clause can be used at a time in a query. While on the other hand, multiple FILTER clauses can be present in a single query.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;EXPRESSION&lt;/span&gt;
&lt;span class="n"&gt;AGGREGATION&lt;/span&gt; &lt;span class="k"&gt;FUNCTION&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;FILTER&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;CLAUSE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;AGGREGATION&lt;/span&gt; &lt;span class="k"&gt;FUNCTION&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="n"&gt;FILTER&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;CLAUSE&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="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;EXPRESSION&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;FILTER&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;LENGTH&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;FILTER&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="k"&gt;LENGTH&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;TEST&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Input table:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;MariaDB&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;TEST&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;----+------------------+----------+&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;ID&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;NAME&lt;/span&gt;             &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;EMPLOYED&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;----+------------------+----------+&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;  &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Drake&lt;/span&gt; &lt;span class="n"&gt;Maverick&lt;/span&gt;   &lt;span class="o"&gt;|&lt;/span&gt;        &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;  &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Nancy&lt;/span&gt; &lt;span class="n"&gt;Peloski&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;        &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;  &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Anakin&lt;/span&gt; &lt;span class="n"&gt;Skywalker&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;        &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;  &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Uchiha&lt;/span&gt; &lt;span class="n"&gt;Obito&lt;/span&gt;     &lt;span class="o"&gt;|&lt;/span&gt;        &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;  &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Anakin&lt;/span&gt; &lt;span class="n"&gt;Skywalker&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;        &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;  &lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Uchiha&lt;/span&gt; &lt;span class="n"&gt;Obito&lt;/span&gt;     &lt;span class="o"&gt;|&lt;/span&gt;        &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;----+------------------+----------+&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;-------+-----------------------+&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;AVG&lt;/span&gt;                   &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;-------+-----------------------+&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;      &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;8333333333333333&lt;/span&gt;   &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;-------+-----------------------+&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In the above query, the number of rows that have an ID other than two is five. We are also printing the average length of names of length greater than 4.&lt;/p&gt;

&lt;h1&gt;
  
  
  Noramalization:
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What is Normalization in SQL?
&lt;/h2&gt;

&lt;p&gt;Let’s begin with why normalization in SQL was introduced originally by discussing the problem it solves. As we know, we’ve relations (or tables) where we store our data, and if you remember one part of DBMS talks about management, we need to manage this data efficiently. Let’s see the wrong way first.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;The Three Problems Or Would Say Anomalies Are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Insertion Anomaly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deletion Anomaly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modification Anomaly&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Insertion anomaly&lt;/strong&gt;  means cases where you can’t insert data unless you have another dependent piece of information. To see this from the above example, we can’t insert teacher’s data unless we have student data (assuming the key is student_id).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deletion anomaly&lt;/strong&gt;  means cases where deleting a record can mistakenly delete other prominent information which is in reality independent in nature. In the above example, deleting a student record will also delete the corresponding teacher’s record and that’s not what we want. That’s because let’s say if a student leaves the school and we’ve to delete their data then doing it would also delete corresponding teacher’s data and that’s not what we want because it doesn’t mean the teacher also left the school.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Modification anomaly&lt;/strong&gt;  means cases when instead of updating a single piece of information at one place we’ve to update it at multiple places. For example, student 1 and student 3 have the same subject, and that’s why they are allotted the same teacher. If we ever want to change this teacher name (for some reason) we’ve to do it at 2 places. Assume if they’re duplicated at tons of places then we’ve to do it at every place to provide consistent data. and this you can guess is really difficult here.&lt;/p&gt;

&lt;p&gt;So, that’s why normalization. So let’s see now what normalization really is and how it solves these anomalies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Normalization and Solving Anomalies
&lt;/h2&gt;

&lt;p&gt;Normalization in SQL is nothing but a technique that prevents above-mentioned anomalies, i.e., insertion, deletion, and modification anomalies to happen and reduces data redundancy. It has some set of rules through which it makes this happen. It divides a big table into smaller tables until it doesn’t follow a set of rules and this process is called normalization.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: Data redundancy is nothing but a form of data that is duplicated at multiple places inside the database.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Normal Form
&lt;/h2&gt;

&lt;p&gt;Please note the last line from the above paragraph “It divides a big table into smaller tables until it doesn’t follow a set of rules ”. What are these rules? Actually, we divide the normalization process into a set of normal forms. A normal form is nothing but a form of a table that follows some norms (rules) that prevent the above anomalies to some extent. We have a list of normal forms,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; 1NF&lt;/li&gt;
&lt;li&gt; 2NF&lt;/li&gt;
&lt;li&gt; 3NF&lt;/li&gt;
&lt;li&gt; BCNF&lt;/li&gt;
&lt;li&gt; 4NF&lt;/li&gt;
&lt;li&gt; 5NF&lt;/li&gt;
&lt;li&gt; 6NF&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Complexity to divide tables into a particular normal form increases as we go down. Also, as we go down, all tables should also follow all the normal forms mentioned above. Please read the above line once more. It’s important!&lt;/p&gt;

&lt;p&gt;Also, in real-life databases that contain multiple tables, they all must be normalized and all the tables should follow the norms, not just one.&lt;/p&gt;

&lt;h1&gt;
  
  
  Indexes :
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;  An  Index  is a special lookup table, built from one or more columns in the database table that speeds up fetching rows from the table or view. There are two types of indexes, Clustered and Non-Clustered Indexes.&lt;/li&gt;
&lt;li&gt;  A  Clustered index  is a type of index in which the data is physically sorted in a table. In the Database, there can be only one clustered index per table.&lt;/li&gt;
&lt;li&gt;  A  Non-Clustered Index  is a type of index in which a separate key-value structure from the actual data table is created, in which the key contains the column values (on which a Non-Clustered Index is declared) and each value corresponding to that key contain a pointer to the data row that contains the actual value.&lt;/li&gt;
&lt;li&gt;  There can be one or more Non-Clustered Indexes per table.&lt;/li&gt;
&lt;li&gt;  In a Clustered Index, the index is the main data and in a non-clustered index, the index is the copy of the main data.&lt;/li&gt;
&lt;li&gt;  Primary Keys  of the table by default are the clustered index, to change the clustered index we have to remove the previous index, and then we can explicitly create a new clustered index.&lt;/li&gt;
&lt;li&gt;  Indexes can be created or dropped with no effect on the actual data table.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Transactions:
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;You might have encountered a situation when your system got crashed due to some hardware or software issues and got rebooted to ensure that all the data is restored in a consistent state.  &lt;em&gt;&lt;strong&gt;This protection of user's data even in case of a system failure marks as one of the major  &lt;a href="https://www.scaler.com/topics/advantages-of-dbms/"&gt;advantages of database management system&lt;/a&gt;&lt;/strong&gt;&lt;/em&gt;. Various transactions are done as a part of manipulating the data in a database, these transactions can be seen as a set of operations that are executed by the user program in DBMS. Execution of a similar transaction multiple times will lead to the generation of multiple transactions. For example, Withdrawing some amount of money from the ATM can be seen as a transaction that can be done multiple times also.&lt;/p&gt;

&lt;h2&gt;
  
  
  Operations in Transaction
&lt;/h2&gt;

&lt;p&gt;A certain set of operations takes place when a transaction is done that is used to perform some logical set of operations. For example: When we go to withdraw money from ATM, we encounter the following set of operations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Transaction Initiated&lt;/li&gt;
&lt;li&gt; You have to insert an ATM card&lt;/li&gt;
&lt;li&gt; Select your choice of language&lt;/li&gt;
&lt;li&gt; Select whether savings or current account&lt;/li&gt;
&lt;li&gt; Enter the amount to withdraw&lt;/li&gt;
&lt;li&gt; Entering your ATM pin&lt;/li&gt;
&lt;li&gt; Transaction processes&lt;/li&gt;
&lt;li&gt; You collect the cash&lt;/li&gt;
&lt;li&gt; You press finish to end transaction&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The above mentioned are the set of operations done by you. But in the case of a transaction in DBMS there are three major operations that are used for a transaction to get executed in an efficient manner. These are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Read/ Access Data&lt;/strong&gt;  &lt;strong&gt;2. Write/ Change Data&lt;/strong&gt;  &lt;strong&gt;3. Commit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's understand the above three sets of operations in a transaction with a real-life example of transferring money from Account1 to Account2.&lt;/p&gt;

&lt;p&gt;Initial balance in both the banks before the start of the transaction&lt;/p&gt;

&lt;p&gt;Account1 - ₹ 5000  Account2 - ₹ 2000&lt;/p&gt;

&lt;p&gt;This data before the start of the transaction is stored in the secondary memory (Hard disk) which once initiated is bought to the primary memory (RAM) of the system for faster and better access.&lt;/p&gt;

&lt;p&gt;Now for a transfer of ₹ 500 from Account1 to Account2 to occur, the following set of operations will take place.&lt;/p&gt;

&lt;p&gt;Read (Account1) --&amp;gt; 5000 Account1 = Account1 - 500 Write (Account1) --&amp;gt; 4500 Read (Account2) --&amp;gt; 2000 Account2 = Account2 + 500 Write (Account2) --&amp;gt; 2500 commit&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The COMMIT statement permanently saves the changes made by the current transaction. When a transaction is successful, COMMIT is applied.&lt;/strong&gt;  If the system fails before a COMMIT is applied, the transaction reaches its previous state after ROLLBACK.&lt;/p&gt;

&lt;p&gt;After commit operation the transaction ends and updated values of Account1 = ₹ 4500 and Account2 = ₹ 2500.  &lt;em&gt;&lt;strong&gt;Every single operation that occurs before the commit is said to be in a partially committed state and is stored in the primary memory (RAM)&lt;/strong&gt;&lt;/em&gt;. After the transaction is committed, the updated data is accepted and updated in the secondary memory (Hard Disk).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If in some case, the transaction failed anywhere before committing, then that transaction gets aborted and have to start from the beginning as it can’t be continued from the previous state of failure. This is known as Roll Back.&lt;/em&gt;  :::&lt;/p&gt;

&lt;h2&gt;
  
  
  Transaction States in DBMS
&lt;/h2&gt;

&lt;p&gt;During the lifetime of a transaction, there are a lot of states to go through. These states update the operating system about the current state of the transaction and also tell the user about how to plan further processing of the transaction. These states decide the regulations which decide the fate of a transaction whether it will commit or abort.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7-T9VkPv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/transaction-in-dbms-scaler.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7-T9VkPv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/transaction-in-dbms-scaler.webp" alt="transaction state in dbms" width="800" height="595"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The ROLLBACK statement undo the changes made by the current transaction. A transaction cannot undo changes after COMMIT execution.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Following are the different types of transaction States :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Active State:&lt;/strong&gt;  When the operations of a transaction are running then the transaction is said to be active state. If all the  &lt;em&gt;read and write&lt;/em&gt;  operations are performed without any error then it progresses to the  &lt;em&gt;partially committed state&lt;/em&gt;, if somehow any operation fails, then it goes to a state known as  &lt;em&gt;failed state&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Partially Committed:&lt;/strong&gt;  After all the read and write operations are completed, the changes which were previously made in the main memory are now made permanent in the database, after which the state will progress to  &lt;em&gt;committed state&lt;/em&gt;  but in case of a failure it will go to the  &lt;em&gt;failed state&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Failed State:&lt;/strong&gt;  If any operation during the transaction fails due to some software or hardware issues, then it goes to the  &lt;em&gt;failed state&lt;/em&gt;  . The occurrence of a failure during a transaction makes a permanent change to data in the database. The changes made into the local memory data are rolled back to the previous consistent state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Aborted State:&lt;/strong&gt;  If the transaction fails during its execution, it goes from  &lt;em&gt;failed state&lt;/em&gt;  to  &lt;em&gt;aborted state&lt;/em&gt;  and because in the previous states all the changes were only made in the main memory, these uncommitted changes are either deleted or rolled back. The transaction at this point can restart and start afresh from the active state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Committed State:&lt;/strong&gt;  If the transaction completes all sets of operations successfully, all the changes made during the partially committed state are permanently stored and the transaction is stated to be completed, thus the transaction can progress to finally get terminated in the  &lt;em&gt;terminated state&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Terminated State:&lt;/strong&gt;  If the transaction gets aborted after roll-back or the transaction comes from the  &lt;em&gt;committed state&lt;/em&gt;, then the database comes to a consistent state and is ready for further new transactions since the previous transaction is now terminated.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Locking mechanism:
&lt;/h1&gt;

&lt;p&gt;We are using MySQL database to execute the Lock mechanism. If you do not have MySQL, download it from  &lt;a href="https://dev.mysql.com/downloads/mysql/"&gt;here&lt;/a&gt;  for your respective operating system.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Creating a Database
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Syntax for creating a database:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;database_name&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;USE&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;database_name&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Creating a database named  &lt;strong&gt;LOCKS&lt;/strong&gt;  in the MySQL database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- creating a LOCKS database in MySQL&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;LOCKS&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- activating the LOCKS database for use&lt;/span&gt;
&lt;span class="n"&gt;USE&lt;/span&gt; &lt;span class="n"&gt;LOCKS&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;MySQL Workbench illustration of the above SQL commands&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i1Lk1niN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/creating-a-database-locks.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i1Lk1niN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/creating-a-database-locks.webp" alt="Creating a database locks" width="800" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Table Creation
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Syntax for creating a table:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;table_name&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;column_name1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;data_type&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;column_name2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;data_type&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;column_name3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;data_type&lt;/span&gt;&lt;span class="o"&gt;&amp;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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creating a table named  &lt;strong&gt;employees&lt;/strong&gt;  in the  &lt;strong&gt;LOCKS&lt;/strong&gt;  database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;emp_id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;emp_name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;dept_no&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OHaMWo12--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/creating-table-employees.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OHaMWo12--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/creating-table-employees.webp" alt="creating table employees" width="800" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Inserting Data into the Table
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Syntax for inserting a row into the table:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;table_name&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;column1_value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;column2_value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;column2_value&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;p&gt;Inserting values in the  &lt;strong&gt;employees&lt;/strong&gt;  table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;"Abhishek"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;"Software Engineer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;102&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;"Yuvraj"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;"Developer Advocate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EkalAmsh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/inserting-values-in-employees-table.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EkalAmsh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/inserting-values-in-employees-table.webp" alt="inserting values in employees table" width="800" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. View Table
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Syntax to view table in the output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;table_name&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Viewing the  &lt;strong&gt;employees&lt;/strong&gt;  table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j5DwRjjP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/view-table.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j5DwRjjP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/view-table.webp" alt="view table" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Applying and Removing Locks
&lt;/h3&gt;

&lt;p&gt;Two types of Lock can be placed on MySQL database resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;READ  Lock&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;WRITE  Lock&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These locks are discussed below:&lt;/p&gt;

&lt;h3&gt;
  
  
  READ  LOCK in MySQL
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  In a  &lt;strong&gt;READ&lt;/strong&gt;  lock  &lt;strong&gt;(also known as a shared lock)&lt;/strong&gt;, the user can only read data from a table, and cannot modify the data.&lt;/li&gt;
&lt;li&gt;  Multiple sessions can obtain a  &lt;strong&gt;READ&lt;/strong&gt;  lock for a table  &lt;strong&gt;simultaneously&lt;/strong&gt;. Other sessions can also read data from the table without having to acquire the lock.&lt;/li&gt;
&lt;li&gt;  The MySQL session with a  &lt;strong&gt;READ&lt;/strong&gt;  lock in place can only read data from the table and cannot write anything until the  &lt;strong&gt;READ&lt;/strong&gt;  lock is freed. Also,  &lt;strong&gt;other sessions will not be unable to write data&lt;/strong&gt;  to the table. Write operations from another session will be kept in a  running...  state until the  &lt;strong&gt;READ&lt;/strong&gt;  lock is freed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Syntax to apply a  READ  lock:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;LOCK&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;table_name&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;READ&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Syntax to remove lock:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;UNLOCK&lt;/span&gt; &lt;span class="n"&gt;TABLES&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;This statement will remove the locks from the table of the active database&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's see how we can apply and remove a  &lt;strong&gt;READ&lt;/strong&gt;  lock from the  &lt;strong&gt;employees&lt;/strong&gt;  table.&lt;/p&gt;

&lt;p&gt;First, create a  MySQL  connection in the MySQL workbench, connect to the  MySQL  database using your password, then use the below syntax to get your current MySQL session id.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;connection_id&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3hI89DAF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/connection-id.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3hI89DAF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/connection-id.webp" alt="connection_id" width="800" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's place a  &lt;strong&gt;READ&lt;/strong&gt;  lock on the  &lt;strong&gt;employees&lt;/strong&gt;  table now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;LOCK&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="k"&gt;READ&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Now, let's try to  &lt;strong&gt;UPDATE&lt;/strong&gt;  the title of  emp_id = 101  to "Advanced Software Engineer".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;"Advanced Software Engineer"&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;emp_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;MySQL throws an error as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;Error&lt;/span&gt; &lt;span class="n"&gt;Code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1099&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="k"&gt;Table&lt;/span&gt; &lt;span class="s1"&gt;'employees'&lt;/span&gt; &lt;span class="n"&gt;was&lt;/span&gt; &lt;span class="n"&gt;locked&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;READ&lt;/span&gt; &lt;span class="k"&gt;lock&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt;&lt;span class="s1"&gt;'t be updated

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O7rdXUsu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/update-error-with-read-lock.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O7rdXUsu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/update-error-with-read-lock.webp" alt="update error with read lock" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see that, we can't write/modify our table contents once we have applied a  &lt;strong&gt;READ&lt;/strong&gt;  lock on the  &lt;strong&gt;employees&lt;/strong&gt;  table. Let's try to modify the content of the table from a different session.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's create another MySQL&lt;/strong&gt;  connection in the MySQL workbench, again connect to the MySQL database using your password, then use the below syntax to get your current MySQL session id.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;connection_id&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ptcpapDD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/connection-id-2.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ptcpapDD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/connection-id-2.webp" alt="connection_id 2" width="800" height="464"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Again, let's try to run the same query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;"Advanced Software Engineer"&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;emp_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;As the first session already has a  &lt;strong&gt;READ&lt;/strong&gt;  lock in place on the  &lt;strong&gt;employees&lt;/strong&gt;  table, MySQL keeps the above update query in the  running...  state on this second session. We can't modify the  &lt;strong&gt;employees&lt;/strong&gt;  table until and unless the lock is  &lt;strong&gt;removed from the table from session 1.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_RYZ6ezx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/update-query-waiting.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_RYZ6ezx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/update-query-waiting.webp" alt="update query waiting" width="800" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can use  &lt;strong&gt;SHOW PROCESSLIST;&lt;/strong&gt;  to get detailed information about the query. We can see this in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AWBwzmSw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/show-process-list.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AWBwzmSw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/show-process-list.webp" alt="show process-list" width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's remove the  &lt;strong&gt;READ&lt;/strong&gt;  lock from the table so that the session 2 query will be executed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;UNLOCK&lt;/span&gt; &lt;span class="n"&gt;TABLES&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TZqU4P04--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/unlock-table.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TZqU4P04--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/unlock-table.webp" alt="UNLOCK TABLE" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's check session 2, we can see that the update query which was in running state is executed now.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---C9VNVQP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/session-2-query-executed.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---C9VNVQP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/session-2-query-executed.webp" alt="session 2 query executed" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  WRITE  LOCK in MySQL
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  In  &lt;strong&gt;WRITE&lt;/strong&gt;  lock  &lt;strong&gt;(also known as an exclusive lock)&lt;/strong&gt;, the user can only write/modify and read the data of a table of the current session only.&lt;/li&gt;
&lt;li&gt;  Other sessions can't write or read the data until the  &lt;strong&gt;WRITE&lt;/strong&gt;  lock is freed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Syntax to apply a  WRITE  lock:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;LOCK&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;table_name&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;WRITE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Syntax to remove lock:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;UNLOCK&lt;/span&gt; &lt;span class="n"&gt;TABLES&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;This statement will  &lt;strong&gt;remove the locks&lt;/strong&gt;  from the table of the active database.&lt;/p&gt;

&lt;p&gt;Now,  &lt;strong&gt;let's see how we can apply&lt;/strong&gt;  a  &lt;strong&gt;WRITE&lt;/strong&gt;  lock on the  &lt;strong&gt;employees&lt;/strong&gt;  table.&lt;/p&gt;

&lt;p&gt;Create two MySQL connections in the  &lt;strong&gt;MySQL workbench&lt;/strong&gt;, and connect to the MySQL database using your password.&lt;/p&gt;

&lt;p&gt;Let's place a  &lt;strong&gt;WRITE&lt;/strong&gt;  lock on the  &lt;strong&gt;employees&lt;/strong&gt;  table now in session 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;LOCK&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="k"&gt;WRITE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Now, let's try to  &lt;strong&gt;INSERT&lt;/strong&gt;  a value into the table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- writing data into the table session 1&lt;/span&gt;
&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;103&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;"Rohan"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;"Application Engineer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;-- reading data from the table session 1&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OeAdRnRa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/write-lock-session-1.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OeAdRnRa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/write-lock-session-1.webp" alt="write lock session 1" width="800" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see that, we can write/modify and read data from the  &lt;strong&gt;employees&lt;/strong&gt;  table from session 1.&lt;/p&gt;

&lt;p&gt;Let's try to  &lt;strong&gt;INSERT&lt;/strong&gt;  another value from session 2 of MySQL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- writing data into the table session 1&lt;/span&gt;
&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;104&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;"Anupam"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;26&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;"Software Engineer II"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;-- reading data from the table session 1&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vwZ9zAV8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/running-in-write-lock.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vwZ9zAV8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/running-in-write-lock.webp" alt="running in write lock" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see that, we can't read or write data into the table from session 2 of the MySQL database once we have applied a  &lt;strong&gt;WRITE&lt;/strong&gt;  lock on the  &lt;strong&gt;employees&lt;/strong&gt;  table.&lt;/p&gt;

&lt;p&gt;Let's remove the  &lt;strong&gt;WRITE&lt;/strong&gt;  lock from the table so that the session 2 query will be executed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;UNLOCK&lt;/span&gt; &lt;span class="n"&gt;TABLES&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Let's check session 2&lt;/strong&gt;, we can see that the update query which was in running state is executed now and a row is inserted into the table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZaSPrXPh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/session-query-executed.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZaSPrXPh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/session-query-executed.webp" alt="session query executed" width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Locks are placed on SQL&lt;/strong&gt;  resources to  &lt;strong&gt;avoid&lt;/strong&gt;  several transactions to access the same resource simultaneously, such as rows  &lt;strong&gt;accessed or manipulated&lt;/strong&gt;  by a transaction by two users at the same time.&lt;/li&gt;
&lt;li&gt;  Locks in SQL are used to adhere to the  &lt;a href="https://www.scaler.com/topics/dbms/acid-properties-in-dbms/"&gt;ACID properties in DBMS&lt;/a&gt;  during a transaction.&lt;/li&gt;
&lt;li&gt;  Locks are applied to the database resources like  &lt;strong&gt;RID&lt;/strong&gt;,  &lt;strong&gt;Key&lt;/strong&gt;,  &lt;strong&gt;Page&lt;/strong&gt;,  &lt;strong&gt;Extent&lt;/strong&gt;,  &lt;strong&gt;Table&lt;/strong&gt;, and  &lt;strong&gt;Database&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;  Locks are of 6 types,  &lt;strong&gt;Extent (X)&lt;/strong&gt;,  &lt;strong&gt;Shared (S)&lt;/strong&gt;,  &lt;strong&gt;Update (U)&lt;/strong&gt;,  &lt;strong&gt;Intent (I)&lt;/strong&gt;,  &lt;strong&gt;Schema (Sch)&lt;/strong&gt;, and  &lt;strong&gt;Bulk Update (BU)&lt;/strong&gt;  lock.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Database Isolation Levels:
&lt;/h1&gt;

&lt;p&gt;Transaction Management is an essential mechanism of relational Database Management Systems. They allow for concurrency whilst maintaining the ACID properties: Atomicity, Consistency, Isolation and Durability. They are used to control and maintain the integrity of each action in a transaction, despite errors that may occur in the system.&lt;/p&gt;

&lt;p&gt;Understanding the various isolation levels and choosing the one that fits your project and allows to achieve better performance or/and guarantee data consistency. Let’s take a look at them and how to define them on a Play 2 with PostgreSQL environment.&lt;/p&gt;

&lt;h4&gt;
  
  
  Isolation Levels
&lt;/h4&gt;

&lt;p&gt;A Transaction consists of a series of read and write operations of database objects that are meant to be atomic: either all actions are carried out or none are. [Raghu p.523]&lt;/p&gt;

&lt;p&gt;For performance reasons a DBMS might interleave transactions, sacrificing the isolation of a transaction from other concurrently executing transactions. They can run of different levels of isolation, each one having a bigger toll on performance although offering a more isolated execution context. DBMS manage transaction concurrency by applying Locks to the required objects. The more elevated isolation level the more locks the transaction will have to acquire in other to execute, thus preventing other concurrent transactions from using the same resources.&lt;/p&gt;

&lt;p&gt;Let’s go over the major  &lt;a href="http://docs.oracle.com/javase/tutorial/jdbc/basics/transactions.html"&gt;JDBC levels&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  TRANSACTION_NONEIn this mode, all read and write operations can execute concurrently.&lt;/li&gt;
&lt;li&gt;  TRANSACTION_READ_COMMITTEDAn operation will only be able to read values that were committed, i.e written by a terminated transaction, before it started. This prevents the problem know as ‘Dirty Read’ (or Write-Read Conflict) which happens when a transaction T1, reads a value written by a another transaction T2, that is not yet committed. If T2 aborts, the value that T1 read will be wrong, thus causing an inconsistency.&lt;/li&gt;
&lt;li&gt;  TRANSACTION_REPEATABLE_READAll operations within the transaction will only be able to read values that were commit previous to the start of the transaction. Adding this limitation solves the ‘Non-repeatable Read’ problem (or Read-Write Conflict). Assume that a transaction T1 reads a given value. If another transaction T2 overwrites that value, and T1 tries to read it again, T1 will get a different value without having changed it.&lt;/li&gt;
&lt;li&gt;  TRANSACTION_SERIALIZABLEThis is the stricter mode. Transactions execute as they would in a serial execution mode. They still execute concurrently but if a transaction T1 tries to access any object that was used by another transaction T2, this will cause T1 to abort. In this mode, as well as preventing the previous issues, also the ‘Phantom Read’ is prevented. A ‘Phantom Read’ occurs when, during the course of a transaction T1, when another transaction T2 inserts or deletes rows. The same operation running on T1 context may yield a different result if executed before and after T2.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Isolation level on Play 2
&lt;/h4&gt;

&lt;p&gt;To set the isolation level of the transactions on a Play 2 project use the following config:&lt;/p&gt;

&lt;p&gt;db.default.isolation="VALUE"&lt;/p&gt;

&lt;p&gt;The allowed values are  &lt;strong&gt;NONE&lt;/strong&gt;,  &lt;strong&gt;READ_COMMITTED_&lt;/strong&gt;&lt;em&gt;,&lt;/em&gt; &lt;strong&gt;_READ_UNCOMMITTED&lt;/strong&gt;,  &lt;strong&gt;REPEATABLE_READ&lt;/strong&gt;  and  &lt;strong&gt;SERIALIZABLE&lt;/strong&gt;. If you get a Configuration Error for an “Unknown isolation level” try adding a space after the value. This is due to a  &lt;a href="https://github.com/playframework/playframework/pull/1930"&gt;bug in the Play DB API&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Optionally, you can set the level per transaction, if you’re writing plain SQL, by defining the isolation level in the BEGIN TRANSACTION statement, like for example:&lt;/p&gt;

&lt;p&gt;BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;&lt;/p&gt;

&lt;p&gt;Or if you using the Slick framework you can set the level in a wrapper for the withTransaction method:&lt;/p&gt;

&lt;p&gt;CodacyDB.database.withTransaction { session =&amp;gt;&lt;br&gt;
        session.conn.setTransactionIsolation(&lt;br&gt;
            java.sql.Connection.TRANSACTION_READ_COMMITTED&lt;br&gt;
        )&lt;br&gt;
  ...&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;We’ve seen and understood different database isolation levels applied to transactions. We’ve specified how this can be achieved in Play using Slick. We’ve used this internally in the process of scaling Codacy to thousands of projects under analysis. Would love to hear what you’re currently using for your application!&lt;/p&gt;
&lt;h1&gt;
  
  
  Triggers:
&lt;/h1&gt;
&lt;h2&gt;
  
  
  What are the Triggers in SQL?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nDJAPK_U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/triggers-in-sql-1.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nDJAPK_U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://scaler.com/topics/images/triggers-in-sql-1.webp" alt="Triggers in SQL" width="800" height="702"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might have encountered situations where you have to constantly check a database table for a particular column to get updated, where, once updated, you have some tasks to do.&lt;/p&gt;

&lt;p&gt;Here the first solution which comes to mind is making a select statement (to check for a specific condition) on the table in an interval of a few seconds or minutes. But this doesn’t seem to be a good choice, right? Instead of us asking the database whether the data has been updated or not, the database should tell us when the data gets updated. This is what exactly triggers do. Triggers, as the name tells us, are stored procedures (procedures are functions that contain SQL statements stored in the database and can return some output) that are executed or fired when some events occur. The user defines these events. The trigger may be set on a row insertion in a table or an update to an existing row and at other points, which we will discuss here. Before moving forward, it is important to discuss what DDL and DML operations are.&lt;/p&gt;

&lt;p&gt;DDL stands for Data definition language, which is used in changing the structure of a table, i.e., creating a table, adding a column to an existing table, or deleting the whole table. However, DML stands for Data manipulation language, which is used to manipulate the data, i.e., insert some new data into the table or update existing data. Also, for deleting some rows, we make use of DML operations.&lt;/p&gt;
&lt;h2&gt;
  
  
  Types of Triggers
&lt;/h2&gt;

&lt;p&gt;The following are the different types of triggers present in SQL.&lt;/p&gt;
&lt;h3&gt;
  
  
  DML Triggers
&lt;/h3&gt;

&lt;p&gt;These triggers fire in response to data manipulation language (DML) statements like INSERT, UPDATE, or DELETE.&lt;/p&gt;
&lt;h2&gt;
  
  
  Display Triggers in SQL
&lt;/h2&gt;

&lt;p&gt;If someone creates a trigger but forgets the trigger's name, then you can find the trigger by running a simple command.&lt;/p&gt;
&lt;h3&gt;
  
  
  Query 6:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SHOW&lt;/span&gt; &lt;span class="n"&gt;TRIGGERS&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'stu%'&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="k"&gt;G&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;


&lt;p&gt;This command will show you the list of all available triggers matching with the string  &lt;strong&gt;‘stu’&lt;/strong&gt;. Note that the \G tag ends the statement just like a semicolon (;). However, since the output table is wide, the \G rotates the table visually to vertical mode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;mysql&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;SHOW&lt;/span&gt; &lt;span class="n"&gt;TRIGGERS&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'stu%'&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="k"&gt;G&lt;/span&gt;
&lt;span class="o"&gt;*********************&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="k"&gt;row&lt;/span&gt; &lt;span class="o"&gt;*********************&lt;/span&gt;
&lt;span class="k"&gt;Trigger&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;student_name&lt;/span&gt;
&lt;span class="n"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;INSERT&lt;/span&gt;
&lt;span class="k"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt;
&lt;span class="k"&gt;Statement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;full_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt;
&lt;span class="n"&gt;Timing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;AFTER&lt;/span&gt;
&lt;span class="n"&gt;Created&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
&lt;span class="n"&gt;sql_mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;NO_ENGINE_SUBSTITUTION&lt;/span&gt;
&lt;span class="k"&gt;Definer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;me&lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;localhost&lt;/span&gt;
&lt;span class="n"&gt;character_set_client&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;utf8&lt;/span&gt;
&lt;span class="n"&gt;collation_connection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;utf8_general_ci&lt;/span&gt;
&lt;span class="k"&gt;Database&lt;/span&gt; &lt;span class="k"&gt;Collation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;latini_swedish_ci&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Drop Triggers in SQL
&lt;/h2&gt;

&lt;p&gt;The deletion of a trigger is quite straightforward. You need to run a simple query to delete a trigger from the database.&lt;/p&gt;

&lt;p&gt;So in our case, as per the example above, the query will be&lt;/p&gt;

&lt;h3&gt;
  
  
  Query 5:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;DROP&lt;/span&gt; &lt;span class="k"&gt;TRIGGER&lt;/span&gt; &lt;span class="n"&gt;student_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;This will erase the trigger from the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Triggers in SQL
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Using triggers, you can eliminate the use of schedulers mostly. Schedulers are applications that keep running in the background and help run a task at a specific time. These timely checks can be removed and instead checked immediately whenever a particular data changes using triggers. It is basically a better replacement for schedulers.&lt;/li&gt;
&lt;li&gt;  These are useful in having additional security checks. There are many critical components in business software, and some of them might risk highly sensitive data if not taken care of properly. Many developers work on a critical component, so some security checks must be done for the data being inserted, updated, or deleted. Here triggers help in maintaining a healthy system by warning about security issues if they exist.&lt;/li&gt;
&lt;li&gt;  One can eliminate the risk of inserting invalid data into a column by having a check for that column or a simple update. Let’s say in the student_name table (where first_name and middle_name are both nullable, i.e., both the columns can accept  &lt;a href="https://www.scaler.com/topics/sql/null-value-in-sql/"&gt;null values&lt;/a&gt;), someone has inserted a row with middle_name keeping the first_name as null. Here the insertion will be successful, but the data is invalid. We can log the error, or also we can move the middle_name value to first_name.&lt;/li&gt;
&lt;li&gt;  These are useful in cleaning activities since we can run some cleanup procedures on listening to deletion events. For example, there are two tables, students and parents. Ideally, if we deleted some students' data from the student's table, the corresponding data from parents (entries of those parents whose children are getting removed) also should get deleted. Since we are prone to such mistakes where we forget to delete data from parent's tables deleting from students, we can handle this very easily using triggers. We can have a trigger on students deletion, wherein on each DELETE operation, we may proceed to remove the corresponding entry from the parents' table.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Disadvantages of Triggers in SQL
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  These are difficult to troubleshoot because they are run automatically, and improper logging will result in unknown updates, which could be very time-consuming to debug in large-scale projects.&lt;/li&gt;
&lt;li&gt;  Triggers increase the overhead of database DML queries. Since for every row we insert, update or delete, it may either do an update or an insertion – say into a new table, or even a row deletion altogether further that might not be required at the moment.&lt;/li&gt;
&lt;li&gt;  Only limited validation can be done at triggers like  &lt;a href="https://www.scaler.com/topics/not-null-in-sql/"&gt;Not Null checks&lt;/a&gt;, Equality checks, Unique checks, etc. Though we can use triggers to handle most of our business use cases, it doesn’t give a full proof solution for every case. Since SQL is a data manipulation language, we cannot expect it to replace programming language dependency for validations. We still need to depend on other validation along with this. Also, in some scenarios, data validation on SQL is costly compared to validation on the service side.&lt;/li&gt;
&lt;/ul&gt;

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