<?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: Jasmin Song</title>
    <description>The latest articles on DEV Community by Jasmin Song (@jsongcodes).</description>
    <link>https://dev.to/jsongcodes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F820191%2Fdf4d2225-fa24-41a5-ae74-c665e5014cee.png</url>
      <title>DEV Community: Jasmin Song</title>
      <link>https://dev.to/jsongcodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jsongcodes"/>
    <language>en</language>
    <item>
      <title>ChatGPT API</title>
      <dc:creator>Jasmin Song</dc:creator>
      <pubDate>Sun, 09 Apr 2023 01:04:41 +0000</pubDate>
      <link>https://dev.to/jsongcodes/chatgpt-api-4ghh</link>
      <guid>https://dev.to/jsongcodes/chatgpt-api-4ghh</guid>
      <description>&lt;h2&gt;
  
  
  What is Artificial Intelligence (AI)?
&lt;/h2&gt;

&lt;p&gt;Artificial intelligence is the simulation of human intelligence processes by machines.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is OpenAI?
&lt;/h2&gt;

&lt;p&gt;OpenAI is a platform that created a model called ChatGPT to interact in a conversational way. As a user, you can ask appropriate questions on ChatGPT and your questions will be answered immediately. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is ChatGPT?
&lt;/h2&gt;

&lt;p&gt;ChatGPT is a revolutionary technology that has been developed by OpenAI, based on the GPT-3.5 architecture. This artificial intelligence model has been trained on a large amount of text data, and it is capable of generating human-like responses to a wide range of queries. (AMAZING!)&lt;/p&gt;

&lt;p&gt;One of the most advantages of ChatGPT is its ability to generate human-like responses. This is achieved through a process called natural language generation (NLG), which allows the model to generate responses that are both grammatically correct and contextually relevant.&lt;/p&gt;

&lt;p&gt;Another advantage of ChatGPT is its ability to learn from its interactions with users. This means that the more it is used, the more accurate and effective it becomes. This is achieved through a process called machine learning, which allows the model to learn from its mistakes and improve its responses over time.&lt;/p&gt;

&lt;p&gt;ChatGPT has already been used in a variety of applications, including customer service chatbots, personal assistants, and even in gaming. In each of these applications, ChatGPT has proven to be effective in providing a natural and engaging user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an API?
&lt;/h2&gt;

&lt;p&gt;API stands for application programming interface, which is a set of definitions and protocols for building and integrating application software.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what?
&lt;/h2&gt;

&lt;p&gt;Well... Now you (may) know enough to harness the power of artificial intelligence in your applications! With this knowledge, you can utilize the ChatGPT API to amplify the functionality of your Ruby on Rails app! This can seem challenging, but fear not! In this step-by-step guide, we will go over the process of integrating ChatGPT API in a Rails app. &lt;/p&gt;

&lt;h2&gt;
  
  
  How do I incorporate the ChatGPT API in my Rails app?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Create an account on OpenAI
&lt;/h3&gt;

&lt;p&gt;Go to &lt;a href="https://auth0.openai.com/u/login/identifier?state=hKFo2SBkQ0ZiTFh2b2lmbDkwY3hCVlBfQUIxRGxxWEhnTFFISaFur3VuaXZlcnNhbC1sb2dpbqN0aWTZIFBQcjBHZ0MxRFRpbU1RanQ3V0RoUzRhSXVWMmpZVy1Vo2NpZNkgRFJpdnNubTJNdTQyVDNLT3BxZHR3QjNOWXZpSFl6d0Q"&gt;OpenAI.com&lt;/a&gt; and create an account.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Get your API key
&lt;/h3&gt;

&lt;p&gt;Click on 'View API Keys' and create a secret key. Paste your API key in a safe place and do not share it with anyone.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Install the OpenAI Ruby Gem
&lt;/h3&gt;

&lt;p&gt;Install the OpenAI Ruby Gem by pasting the following to your Gemfile:&lt;br&gt;
&lt;/p&gt;

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

gem "dry-initializer"

gem 'figaro'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run bundle install to install the gem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Create an OpenaiPrompt class
&lt;/h3&gt;

&lt;p&gt;In your app/services folder, create a file named openai_prompt.rb and paste the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class OpenaiPrompt
  extend Dry::Initializer

  URL = "https://api.openai.com/v1/completions"

  param :prompt

  option :model, default: proc { "text-davinci-003" }
  option :max_tokens, default: proc { 1000 }
  option :temperature, default: proc { 0 }

  def call
    connection =
      Faraday.new do |faraday|
        faraday.ssl[:verify] = false
        faraday.headers = headers
      end
    response = connection.post(URL, body)
    json = JSON.parse(response.body)
    json["choices"].first["text"]
  end

  private

  def body
    {
      model: model,
      prompt: prompt,
      max_tokens: max_tokens,
      temperature: temperature
    }.to_json
  end

  def headers
    {
      "Content-Type" =&amp;gt; "application/json",
      "Authorization" =&amp;gt; "Bearer #{ENV['OPENAI_ACCESS_TOKEN']}",
      "OpenAI-Organization" =&amp;gt; ENV['OPENAI_ORGANIZATION_ID']
    }
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Create an environment variable
&lt;/h3&gt;

&lt;p&gt;In your config/application.yml file, paste the following code and replace the string with your secret ChatGPT API key that you stored earlier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OPENAI_ACCESS_TOKEN: 'your secret api key here'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 6: Open your Ruby console
&lt;/h3&gt;

&lt;p&gt;In your terminal, type 'rails c' and paste the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OpenaiPrompt.new('Why is AI so important?').call
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OpenaiPrompt.new('What questions can I ask you?').call
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What can I do with this?
&lt;/h2&gt;

&lt;p&gt;As a developer, you can utilize the ChatGPT API to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generating codes.&lt;/li&gt;
&lt;li&gt;Generating documents.&lt;/li&gt;
&lt;li&gt;Writing test cases.&lt;/li&gt;
&lt;li&gt;Simplifying codes and explaining complex code snippets.&lt;/li&gt;
&lt;li&gt;Generating alternative codes.&lt;/li&gt;
&lt;li&gt;Tracking down bugs/applying good code practices.&lt;/li&gt;
&lt;li&gt;Information gathering/research.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In conclusion, ChatGPT is a powerful tool that has the potential to revolutionize the way we interact with technology. Its ability to generate human-like responses and learn from its interactions makes it a valuable resource for businesses and individuals alike. As AI technology continues to advance, we can expect ChatGPT to become even more sophisticated and effective in the years to come.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building the backend for a full stack web app</title>
      <dc:creator>Jasmin Song</dc:creator>
      <pubDate>Sun, 26 Feb 2023 01:59:51 +0000</pubDate>
      <link>https://dev.to/jsongcodes/building-a-backend-for-a-full-stack-web-app-4if</link>
      <guid>https://dev.to/jsongcodes/building-a-backend-for-a-full-stack-web-app-4if</guid>
      <description>&lt;p&gt;I made my second full stack project using React and Rails. It has been quite the journey. I implemented my knowledge of React, HTML, CSS, JavaScript for the frontend. For the backend, I utilized my new knowledge of Ruby on Rails. Today, we will focus on the backend.&lt;/p&gt;

&lt;p&gt;During this journey, I learned about Rails fundamentals, CRUD with Rails, validations, error handling, Active Record associations, serialization, authorization, and authentication.&lt;/p&gt;

&lt;p&gt;Whew. That's a lot. In this blog post, I'll walk you through each step I took to create my the backend of my full stack web app, Everything ELA. Everything ELA is a virtual space where students can read, comment, and post about English Language Arts (ELA) topics. It is a website for the students in my virtual school. Students are able to register, login, create posts, read posts, and log out. Comments are able to be created, read, updated, and deleted. &lt;/p&gt;

&lt;p&gt;First, I made sure I had Ruby 2.7.4, NodeJS (v16), and npm set up. I cloned a project template repository and created a new remote repository on Github. I ran bundle install, rails db:create, and npm install.&lt;/p&gt;

&lt;p&gt;At that point, I was all set up! This is where the fun started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Models&lt;/strong&gt;&lt;br&gt;
I created my three models: Student, Comment, and Post and their tables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create_table "comments", force: :cascade do |t|
    t.string "body"
    t.integer "post_id"
    t.integer "student_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end
&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;create_table "posts", force: :cascade do |t|
    t.string "title"
    t.string "image"
    t.string "body"
    t.integer "student_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end
&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;create_table "students", force: :cascade do |t|
    t.string "username"
    t.string "password_digest"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I knew I needed Active Record Associations so I planned that out.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Comment &amp;lt; ApplicationRecord
  belongs_to :student
  belongs_to :post
end
&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;class Post &amp;lt; ApplicationRecord
  has_many :comments
  has_many :students, through: :comments
end
&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;class Student &amp;lt; ApplicationRecord
  has_many :comments
  has_many :posts, through: :comments
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Controllers&lt;/strong&gt;&lt;br&gt;
I then created my controllers using the rails g command. I knew that I wanted full CRUD capabilities for the Comments, create and read capabilities for the Students and Posts, and I needed a SessionsController for login and logout capabilities. I set up these methods in my controllers after creating them.&lt;br&gt;
&lt;/p&gt;

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

    def index

    end

    def create

    end

    def update

    end

    def destroy

    end

end
&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;class PostsController &amp;lt; ApplicationController
    def index

    end

    def show

    end

    def create

    end

end
&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;class SessionsController &amp;lt; ApplicationController

    def create

    end 

    def destroy

    end

end
&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;class StudentsController &amp;lt; ApplicationController

    def show

    end

    def create

    end

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Rails Routing&lt;/strong&gt;&lt;br&gt;
In the config/routes.rb file, I created my routes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources :comments
  resources :posts, only: [:index, :show, :create]
  post "/signup", to: "students#create"
  get "/me", to: "students#show"
  post "/login", to: "sessions#create"
  delete "/logout", to: "sessions#destroy"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Validations&lt;/strong&gt;&lt;br&gt;
Now, onto validations. Validations are special method calls  consist of code that performs the job of protecting the database from invalid data.&lt;/p&gt;

&lt;p&gt;For example, I want to make sure that all comments are longer than 1 character, posts have a title, and students have unique usernames.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Comment &amp;lt; ApplicationRecord
    validates :body, length: { minimum: 1 }

    belongs_to :student
    belongs_to :post
end
&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;class Post &amp;lt; ApplicationRecord
    validates :title, presence: true

    has_many :comments
    has_many :students, through: :comments
end
&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;class Student &amp;lt; ApplicationRecord

    has_many :comments, dependent: :destroy
    has_many :posts, through: :comments

    validates :username, presence: true, uniqueness: true
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Error Handling&lt;/strong&gt;&lt;br&gt;
I then updated the controller action to check the validity of our model when it is created, and respond appropriately:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ApplicationController &amp;lt; ActionController::API
    include ActionController::Cookies

    rescue_from ActiveRecord::RecordInvalid, with: :render_unprocessable_entity_response
    rescue_from ActiveRecord::RecordNotFound, with: :render_not_found_response

    def render_unprocessable_entity_response(e)
        render json: {errors: e.record.errors.full_messages}, status: :unprocessable_entity
    end

    def render_not_found_response(invalid)
        render json: { errors: invalid }, status: :not_found
    end

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Serialization&lt;/strong&gt;&lt;br&gt;
Serialization  is the process of translating data structures or objects into a format that can be stored or transmitted and reconstructed later. We need to send a standardized response to the API consumers to make sense of the transferred data. We need Active Model Serializers to structure the data we send back to the client appropriately. (In this case, JSON.)&lt;/p&gt;

&lt;p&gt;I created serializers using the rails g command in the terminal. I then added the desired attributes and the necessary Active Record associations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CommentSerializer &amp;lt; ActiveModel::Serializer
  attributes :id, :body

  has_one :student
end
&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;class PostSerializer &amp;lt; ActiveModel::Serializer
 attributes :id, :title, :image, :body, :student_id
end
&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;class PostWithCommentsSerializer &amp;lt; ActiveModel::Serializer
  attributes :id, :title, :body

  has_many :comments
end
&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;class StudentSerializer &amp;lt; ActiveModel::Serializer
  attributes :id, :username
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Authentication&lt;/strong&gt;&lt;br&gt;
Authentication is how our application can confirm that our users are who they say they are. Simply put, we use usernames and passwords to verify our users. (In our case, students.)&lt;br&gt;
&lt;/p&gt;

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

    skip_before_action :authorize, only: :create

    def create
        student = Student.find_by(username: params[:username])

        if student&amp;amp;.authenticate(params[:password])
            session[:student_id] = student.id
            render json: student, status: :created
        else 
            render json: {errors: ["Invalid username or password"] }, status: :unauthorized
        end 
    end 

    def destroy
        session.delete :student_id
        head :no_content
    end

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Authorization&lt;/strong&gt;&lt;br&gt;
Authorization gives certain users permission to access specific resources. To authorize a student for specific actions, we can use the :student_id saved in the session hash. We can use a before_action filter to run some code that will check the :students_id in the session and only authorize students to run those actions if they are logged in.&lt;/p&gt;

&lt;p&gt;And that's it! I used Rails fundamentals, CRUD with Rails, validations, error handling, Active Record associations, serialization, authorization, and authentication to build the backend of my web app.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Ruby Object Oriented Programming</title>
      <dc:creator>Jasmin Song</dc:creator>
      <pubDate>Wed, 04 Jan 2023 01:06:01 +0000</pubDate>
      <link>https://dev.to/jsongcodes/ruby-object-oriented-programming-4am7</link>
      <guid>https://dev.to/jsongcodes/ruby-object-oriented-programming-4am7</guid>
      <description>&lt;p&gt;Ruby is an object oriented programming language. Everything in Ruby is an object. Objects contain data, such as attributes and methods. In other words, objects are the basic building-blocks of Ruby code. In Ruby, we are sending messages to objects.&lt;/p&gt;

&lt;p&gt;Object oriented programming structures code so that its functionality can be used throughout the application. It also is beneficial for when programs change and grow. Object oriented programming allows us to organize our code to have classes and create specific instances of those classes. &lt;/p&gt;

&lt;p&gt;In this blog post, we will talk about the principles of object oriented programming. Hopefully you leave with a better idea of why it is helpful, and how it relates to the real world!&lt;/p&gt;

&lt;h2&gt;
  
  
  Classes
&lt;/h2&gt;

&lt;p&gt;Classes are a way we construct objects in object oriented programming. We are encapsulating what something is. For example, a cat class would look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmwd0r6ihdv0dkxwvx615.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmwd0r6ihdv0dkxwvx615.png" alt="Image description" width="788" height="116"&gt;&lt;/a&gt;&lt;br&gt;
Here, we are building the Cat class. The keyword &lt;code&gt;end&lt;/code&gt; declares that the block is over. We can create a Cat now. Now we can add lines 5 through 7 and when we &lt;code&gt;puts&lt;/code&gt; Udon, we see an object of a new cat. We also see a memory address of where the object exists.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbe8owyidvufqhn6u9qus.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbe8owyidvufqhn6u9qus.png" alt="Image description" width="800" height="1183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Instances
&lt;/h2&gt;

&lt;p&gt;If we make another cat, we get a unique address for the new object. We are making specific instances of a cat.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpkdr4iw06zwnsyi9gqqg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpkdr4iw06zwnsyi9gqqg.png" alt="Image description" width="774" height="1170"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;class&lt;/strong&gt; is a blueprint and the Udon and Minari objects are specific &lt;strong&gt;instances&lt;/strong&gt; of our Cat class. However, our Cats class should not be blank. A class is like a blueprint that defines how to build an object. Our cat class should have specific &lt;strong&gt;methods&lt;/strong&gt;, or functions, to describe what the cats do. So let's add some methods!&lt;/p&gt;

&lt;h2&gt;
  
  
  Initialize
&lt;/h2&gt;

&lt;p&gt;If we want instances of our class to be created with data, we need to define our initialize method. This ensures that whenever .new is used, #initialize is called.&lt;/p&gt;

&lt;p&gt;If we want to define the initial property of the cat, we need to do that in a constructor of a class. In Ruby, the constructor is a function called &lt;strong&gt;initialize&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs8tfg5ckn1glo13d4tqz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs8tfg5ckn1glo13d4tqz.png" alt="Image description" width="692" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Instance Methods
&lt;/h2&gt;

&lt;p&gt;Instance methods are responsible for doing something for each cat instance.&lt;/p&gt;

&lt;p&gt;Here, we are stating that each cat has four legs, two ears, and has a tail. If we want to access these properties, we are unable to because by default, these instance properties are private.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getters and Setters
&lt;/h2&gt;

&lt;p&gt;Getter and setter methods enable us to set attributes to our objects and get the value of those attributes.&lt;/p&gt;

&lt;p&gt;In order to get and set the values in our initialize method, we need to use &lt;strong&gt;getter&lt;/strong&gt; and &lt;strong&gt;setter&lt;/strong&gt; methods. &lt;/p&gt;

&lt;p&gt;The setter method is defined with an equal sign and followed by the parameter. The equal sign is part of the method's name. The getter belongs to every instance of our Cat class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsfhwjx3aak6txvo0c678.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsfhwjx3aak6txvo0c678.png" alt="Image description" width="796" height="1258"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have set the setter and getter methods, when we puts Udon.legs and Minari.legs, we get the value of legs. We are also able to set the cats' legs, by saying Udon now has 3 legs. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl4xjr6yjhoyjfa6pjzhj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl4xjr6yjhoyjfa6pjzhj.png" alt="Image description" width="800" height="629"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Local Variables
&lt;/h2&gt;

&lt;p&gt;Our initialize method can take in arguments. If it has a name property, we can say &lt;a class="mentioned-user" href="https://dev.to/name"&gt;@name&lt;/a&gt;=name. without the @ symbol, it is a local variable. With the @ symbol, it is available for each cat.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5g8cmymljbtwaaotceof.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5g8cmymljbtwaaotceof.png" alt="Image description" width="800" height="1227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So now if we want to add a name for each cat, we add an instance property. The instance of Udon has a different instance than Minari. So each cat has its own name.&lt;/p&gt;

&lt;p&gt;Now if we want it to have a variable that is available to both cats, then we create a class variable using two @ signs. @@&lt;/p&gt;

&lt;p&gt;Here, we will add a class variable @@total_cats and make it equal to zero. Then in our initialize method, we will add @@total_cats += 1. We will also need a class method, a method that belongs to cats. Here, I called it Cat.total on lines 13 through 15.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F49l0f0xjj5gr7zsiawi5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F49l0f0xjj5gr7zsiawi5.png" alt="Image description" width="786" height="1184"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we see the total cats as two.&lt;/p&gt;

&lt;p&gt;Cat.new and Cat.total are class methods because we are calling it on the Cat class. As mentioned before, in Ruby, the class in itself is an object.&lt;/p&gt;

&lt;p&gt;Object oriented programming uses objects that contain data, attributes, and functions (or methods). Objects are the building blocks of Ruby since everything in Ruby is an object. Object oriented programming allows programmers to form models of real world problems/concepts.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>chatgpt</category>
      <category>llm</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Controlled Forms</title>
      <dc:creator>Jasmin Song</dc:creator>
      <pubDate>Sat, 08 Oct 2022 17:38:29 +0000</pubDate>
      <link>https://dev.to/jsongcodes/controlled-forms-19n9</link>
      <guid>https://dev.to/jsongcodes/controlled-forms-19n9</guid>
      <description>&lt;p&gt;A controlled form is a form that derives its input values from state. While this means you have to type a bit more code, you can now pass the value to other UI elements too, or reset it from other event handlers.&lt;/p&gt;

&lt;p&gt;For controlled inputs you will need a corresponding state and then a class method to update that state with changes. Form input values can be set to state values and then updated via React events.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4geCDmp3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ivwyorhix0c230yvjl6a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4geCDmp3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ivwyorhix0c230yvjl6a.png" alt="Image description" width="501" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To access the fields in the event handler, you can use the event.target.name and event.target.value syntax.&lt;/p&gt;

&lt;p&gt;To update the state, you can use square brackets [bracket notation] around the property name.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SFsM4FeH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xvoie1u5rrrjwmxu892.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SFsM4FeH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xvoie1u5rrrjwmxu892.png" alt="Image description" width="490" height="126"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In React:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the value of a textarea is placed in a value attribute. &lt;/li&gt;
&lt;li&gt;the selected value is defined with a value attribute on the select tag:&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>The 3 Pillars of Web Programming</title>
      <dc:creator>Jasmin Song</dc:creator>
      <pubDate>Thu, 02 Jun 2022 13:38:50 +0000</pubDate>
      <link>https://dev.to/jsongcodes/the-3-pillars-of-web-programming-4p2h</link>
      <guid>https://dev.to/jsongcodes/the-3-pillars-of-web-programming-4p2h</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gKzbA2za--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/08shixbnkui0x8bri4r6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gKzbA2za--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/08shixbnkui0x8bri4r6.png" alt="Image description" width="800" height="611"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The three essential pillars of Web Programming are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Recognizing Events&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Actions that make JavaScript do work.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1. Manipulating the DOM&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The update Javascript was told to do.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1. Communicating with the Sever&lt;/strong&gt;&lt;/p&gt;

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

&lt;h2&gt;
  
  
  What is the DOM?
&lt;/h2&gt;

&lt;p&gt;When HTML document gets loaded into the browser, the browser creates the DOM: &lt;strong&gt;D&lt;/strong&gt;ocument &lt;strong&gt;O&lt;/strong&gt;bject &lt;strong&gt;M&lt;/strong&gt;odel. DOM allows JavaScript to interact with the HTML document. When we make changes to the DOM, the DOM will make changes to the document, or our webpage.&lt;/p&gt;

&lt;p&gt;The DOM is a "middle layer" that presents the HTML, CSS and JavaScript loaded by the browser when we visit a page. We normally interact with it through the document object.&lt;/p&gt;

&lt;p&gt;All items in the DOM are defined as nodes. The document itself is a document node, which is the root of all other nodes.&lt;/p&gt;

&lt;p&gt;The DOM consists of a tree structure of nested nodes, which is often referred to as the DOM tree. The nodes in the DOM are referred to as parents, children, and siblings, depending on their relation to other nodes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IFftTFbj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/agc786euvsn9jtdj6mh6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IFftTFbj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/agc786euvsn9jtdj6mh6.png" alt="Image description" width="800" height="680"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NDf0JSCn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1j74e133b5ykcfkqrdow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NDf0JSCn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1j74e133b5ykcfkqrdow.png" alt="Image description" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The HTML DOM is a standard for how to get, change, add, or delete HTML elements.&lt;br&gt;
DOM programming is using JavaScript to:&lt;/p&gt;

&lt;p&gt;Ask the DOM to find or select an HTML element or elements in the rendered page&lt;br&gt;
Remove the selected element(s) and/or insert new element(s)&lt;br&gt;
Adjust a property of the selected element(s)&lt;/p&gt;

&lt;p&gt;There are 2 ways you can add elements to the page:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;append() is the method we use to add elements to the body.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;With append(), you can append strings and multiple things.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;appendChild() is another way.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;With appendChild(), you can only append one thing at a time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MfeiLJF---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpyrgcoq6x57wi9s7wxr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MfeiLJF---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpyrgcoq6x57wi9s7wxr.png" alt="Image description" width="800" height="97"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How do you make an element?&lt;br&gt;
document.createElement('') and pass the element you want to create.&lt;/p&gt;

&lt;p&gt;You must append the elements!&lt;br&gt;
body.append(div)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jucf7I7K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6i45rr5g8sru98krjnuz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jucf7I7K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6i45rr5g8sru98krjnuz.png" alt="Image description" width="800" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Select an Element With JavaScript&lt;/strong&gt;&lt;br&gt;
In the Console type:&lt;br&gt;
document.querySelector('div');&lt;br&gt;
It will return something like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tMDmkTag--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2g002xrn6ruvtqn6o9l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tMDmkTag--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2g002xrn6ruvtqn6o9l.png" alt="Image description" width="502" height="144"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we run document.querySelector('div');, it returns the DOM node, which is also a JavaScript object. This means that it can now have methods called on it! This is called method chaining. Let's use method chaining to remove our node from the DOM.&lt;/p&gt;

&lt;p&gt;We can store the node references in the variables like this:&lt;br&gt;
const div = document.querySelector('div');&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Delete an Element with JavaScript&lt;/strong&gt;&lt;br&gt;
If we type: &lt;br&gt;
document.querySelector('div').remove();&lt;br&gt;
We can delete the div.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P9FbIl7f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/niptg2n8wiceib941fw1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P9FbIl7f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/niptg2n8wiceib941fw1.png" alt="Image description" width="492" height="106"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An event in JavaScript is an action the user has taken. When the user hovers their mouse over an element, or clicks on an element, or presses a specific key on the keyboard, these are all types of events. In this particular case, we want our button to listen and be ready to perform an action when the user clicks on it. We can do this by adding an event listener to our button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--va1qYj5c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pcd0hrr96z1jlq8upg5t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--va1qYj5c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pcd0hrr96z1jlq8upg5t.png" alt="Image description" width="454" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HTTP Overview&lt;br&gt;
Communication between different clients and different servers is only possible because the way browsers and servers talk is controlled by a contract, or protocol. Your server will receive requests from the browser that follow HTTP. It then responds with an HTTP response that all browsers are able to parse.&lt;/p&gt;

&lt;p&gt;HTTP is the "language" browsers speak. Every time you load a web page, you are making an HTTP request to the site's server, and the server sends back an HTTP response. When you use fetch in JavaScript, you are also making an HTTP request.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hrwOpd-v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ky5mce3lzq4mkhl3333s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hrwOpd-v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ky5mce3lzq4mkhl3333s.png" alt="Image description" width="800" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HTTP Verbs&lt;br&gt;
When making a web request, in addition to the path, you also need to specify the action you would like the server to perform. We do this using HTTP Verbs (Links to an external site.), also referred to as request methods. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jaIXMEi8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ertgq5ostvp8v3dnunet.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jaIXMEi8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ertgq5ostvp8v3dnunet.png" alt="Image description" width="800" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using the Fetch API&lt;br&gt;
The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network.&lt;/p&gt;

&lt;p&gt;fetch('&lt;a href="http://example.com/movies.json'"&gt;http://example.com/movies.json'&lt;/a&gt;)&lt;br&gt;
  .then(response =&amp;gt; response.json())&lt;br&gt;
  .then(data =&amp;gt; console.log(data));&lt;/p&gt;

&lt;p&gt;Here we are fetching a JSON file across the network and printing it to the console. The simplest use of fetch() takes one argument — the path to the resource you want to fetch — and does not directly return the JSON response body but instead returns a promise that resolves with a Response object.&lt;/p&gt;

&lt;p&gt;The Response object does not directly contain the actual JSON response body but is a representation of the entire HTTP response. So, to extract the JSON body content from the Response object, we use the json() method, which returns a second promise that resolves with the result of parsing the response body text as JSON.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Scope</title>
      <dc:creator>Jasmin Song</dc:creator>
      <pubDate>Mon, 23 May 2022 14:05:49 +0000</pubDate>
      <link>https://dev.to/jsongcodes/scope-3hpi</link>
      <guid>https://dev.to/jsongcodes/scope-3hpi</guid>
      <description>&lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt; is what we can access and where we can access it. It is the concept of where something is available.&lt;/p&gt;

&lt;p&gt;Through the &lt;strong&gt;scope chain&lt;/strong&gt;, a function has access to all variables and functions declared in its &lt;strong&gt;outer scope&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tUFMQRke--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uv2wguudjgflyq43jqfr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tUFMQRke--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uv2wguudjgflyq43jqfr.png" alt="Image description" width="514" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3 levels of scope
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Global
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Accessible in every scope&lt;/li&gt;
&lt;li&gt;Outermost scope&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Functional
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Accessible within a function&lt;/li&gt;
&lt;li&gt;If you have 2 functions, they have their own unique scopes. You can't access the same items from each other's boxes. &lt;/li&gt;
&lt;li&gt;Specific to a single function&lt;/li&gt;
&lt;li&gt;Can't be accessed by anything in outer scopes&lt;/li&gt;
&lt;li&gt;Every function creates its own scope, and any variables or functions you declare inside of the function will not be available outside of it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Block
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Accessible within a block&lt;/li&gt;
&lt;li&gt;Specific blocks&lt;/li&gt;
&lt;li&gt;Can't be accessed by anything in outer scopes&lt;/li&gt;
&lt;li&gt;Variables declared with &lt;em&gt;var&lt;/em&gt; are not block scoped. Variables declared with &lt;em&gt;const&lt;/em&gt; and &lt;em&gt;let&lt;/em&gt; are block scoped.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Lexical Scope
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Can access variables in outer scope&lt;/li&gt;
&lt;li&gt;Can't access variable in nested scope&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a_pJx_Ze--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/41v2zlcdv70uahrm8yc1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a_pJx_Ze--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/41v2zlcdv70uahrm8yc1.png" alt="Image description" width="800" height="621"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cannot access variables in parent scope. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oNmRZQS3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ke9mlv4npiq6qiqkeuns.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oNmRZQS3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ke9mlv4npiq6qiqkeuns.png" alt="Image description" width="800" height="556"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Functions</title>
      <dc:creator>Jasmin Song</dc:creator>
      <pubDate>Mon, 23 May 2022 13:56:19 +0000</pubDate>
      <link>https://dev.to/jsongcodes/functions-iek</link>
      <guid>https://dev.to/jsongcodes/functions-iek</guid>
      <description>&lt;p&gt;Functions allow us to wrap and reuse parts of our code. Allows us to control the flow of execution. We get to control when, where, and why our code runs. &lt;/p&gt;

&lt;p&gt;A function is an object that contains a sequence of JavaScript statements. We can execute or call it multiple times.&lt;/p&gt;

&lt;p&gt;call, invoke, or execute functions means to run the pieces that make it.&lt;/p&gt;

&lt;p&gt;using &lt;strong&gt;function declaration&lt;/strong&gt; using the function keyword:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Need 2 main pieces: () and {}&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;can invoke function before and after it's been defined.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;using a &lt;strong&gt;variable&lt;/strong&gt; with function expression: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;can only be called after the function declaration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;return ends our function&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;not hoisted&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;if we don't specify the return value, end up getting undefined. if we do specify the return value, we get that value.&lt;/p&gt;

&lt;p&gt;() is the invocation operator. It invokes the function.&lt;/p&gt;

&lt;p&gt;the function call can actually come before the function declaration in the code file, due to hoisting. But it needs to exist somewhere; if you try to call a function that hasn't been declared somewhere in the code, you'll get an error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hoisting
&lt;/h2&gt;

&lt;p&gt;JavaScript's ability to call functions before they appear in the code is called hoisting. For hoisting to work, the function must be defined using a function declaration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Arrow Functions
&lt;/h2&gt;

&lt;p&gt;Created with an arrow and using an assignment operator&lt;br&gt;
cannot be hoisted&lt;/p&gt;

&lt;p&gt;when there are no braces, arrow functions have an implicit return, i.e., they automatically return the result of the last expression! This is the only situation in which a JavaScript function doesn't require explicit return with the return keyword.&lt;/p&gt;

&lt;h2&gt;
  
  
  Callback Functions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;when functions are passed as an argument to a function
functions are objects&lt;/li&gt;
&lt;li&gt;is not invoked immediately&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Anonymous Functions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;functions functions without an identifier or a name&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Variables</title>
      <dc:creator>Jasmin Song</dc:creator>
      <pubDate>Fri, 20 May 2022 14:55:13 +0000</pubDate>
      <link>https://dev.to/jsongcodes/variables-5a77</link>
      <guid>https://dev.to/jsongcodes/variables-5a77</guid>
      <description>&lt;p&gt;A &lt;strong&gt;variable&lt;/strong&gt; is a container where we can store a value.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;let&lt;/em&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;can be reassigned but not redeclared&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TKwbPfow--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ec4gy7ip1a99sofhn40.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TKwbPfow--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ec4gy7ip1a99sofhn40.png" alt="Image description" width="328" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;can declare &lt;em&gt;let&lt;/em&gt; with a value when declaring the variable, or declare it and not give it a value. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;with let arrays: you can update it at any point. let is the var keyword but block-scoped. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;const&lt;/em&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;cannot be reassigned or redeclared&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W3_tIIwW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ccrc1ayiqkdk0l8c82f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W3_tIIwW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ccrc1ayiqkdk0l8c82f.png" alt="Image description" width="648" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;cannot declare const with a value and not give it a value. can't say const chicken; because const is supposed to say constant, so you need to know ahead of time what the value is going to be.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;const array: the values can be updating the values/pushing onto the array. You're still changing the array. you're not updating the reference. pointing to the same array/object in memory. can't change the reference. We are not able to reassign the array itself but we can reassign any of its elements. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;var&lt;/em&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;declares variables&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;declares a function-scoped or globally-scoped variable, optionally initializing it to a value.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JiAtMNOB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6s97kbga61d933igkzyo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JiAtMNOB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6s97kbga61d933igkzyo.png" alt="Image description" width="544" height="644"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;can declare a var with a value when you declare the variable, or declare it and not give it a value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;you can redeclare the variable at any time&lt;br&gt;
var x = 10; var x = "hi";&lt;br&gt;
You're not just updating/reassigning x, you are completely redeclaring it. can't do that with let or const.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;hoisting&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;a variable can be used before it has been declared&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;when variables are set to undefined. declared before the rest of the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;let and const get hoisted. they are not set to undefined like var. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;var is scoped to the current execution context. scoped to their enclosing function if they are in a function. if not, they are part of the global scope.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;let and const are block scoped. var is not block scoped. it is scoped to the current execution context.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;when you declare var in global scope, it is added to the window object. const and let are not in the window object.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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