<?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>Forem: gyi2521</title>
    <description>The latest articles on Forem by gyi2521 (@gyi2521).</description>
    <link>https://forem.com/gyi2521</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%2F101054%2F423fcfdf-7ebf-4675-a55d-f5012611ddf2.jpg</url>
      <title>Forem: gyi2521</title>
      <link>https://forem.com/gyi2521</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/gyi2521"/>
    <language>en</language>
    <item>
      <title>ES6 - Template Literals</title>
      <dc:creator>gyi2521</dc:creator>
      <pubDate>Tue, 27 Nov 2018 18:55:34 +0000</pubDate>
      <link>https://forem.com/gyi2521/es6---template-literals-4ljf</link>
      <guid>https://forem.com/gyi2521/es6---template-literals-4ljf</guid>
      <description>

&lt;p&gt;The one of my favorite features in ES6 or ECMAScript 2015 is 'Template Literals'. Before I learn about 'Template Literals' in my Coding Boot-camp recently, I used to use string concatenation in JavaScript as following:&lt;/p&gt;

&lt;pre&gt; 
var user = {
  name: 'Gina',
  hobby: 'Traveling',

};

console.log('Hi, I\'m ' + user.name + '! My hobby is "' + user.hobby + '".');

//Hi, I'm Gina! My hobby is "Traveling".
&lt;/pre&gt;

&lt;p&gt;Now with template literals, I can write as following:&lt;/p&gt;

&lt;pre&gt;
var user = {
  name: 'Gina',
  hobby: 'Traveling',

};

console.log(`Hi, I'm ${user.name}! My hobby is "${user.hobby}".`);

//Hi, I'm Gina! My hobby is "Traveling".
&lt;/pre&gt;

&lt;p&gt;Both examples give the same result, but do you see how readable the second example is using the 'Template Literals'?  When you are using string concatenation, you need to use the backslash(\) to escape special characters. Because of the duplicate usage of some of the characters, reading and understanding the text could be challenging. With Template Literals, you construct the string as you are writing a plain English sentence inside back-ticks(``). If you want to add variables, just use a dollar sign followed by curly brackets.  You can even add a simple Javascript statement if it is necessary as following:&lt;/p&gt;

&lt;pre&gt;
console.log(`Two times seven is ${2*7}.`);

// Two times seven is 14.

&lt;/pre&gt;

&lt;p&gt;In addition the line breaks got much easier with Template Literals.&lt;/p&gt;

&lt;pre&gt;
With Template Literals:

console.log(`Hi Gina,
Good luck with your presentation today!
                          -your friend`)

//Hi Gina,
Good luck with your presentation today!
                          -your friend
&lt;/pre&gt;

&lt;pre&gt;
Without Template Literals:

console.log('Hi Gina, \n' +
'Good luck with your presentation today! \n' +
'\t\t\t\t\t\t   -your friend')

//Hi Gina,
Good luck with your presentation today!
                          -your friend
&lt;/pre&gt;

&lt;p&gt;Do you see how easy it is to read? With template literals, you create text as you write a note to your friend without using new line characters(\n) or tabs(\t).  I have not encountered any issues with this feature so far and I really enjoy using it. If you have not tried it yet, you should definitely give a try...&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;


</description>
      <category>templateliterals</category>
      <category>javascript</category>
      <category>es6</category>
      <category>beginners</category>
    </item>
    <item>
      <title>MySQL vs. MongoDB</title>
      <dc:creator>gyi2521</dc:creator>
      <pubDate>Thu, 15 Nov 2018 21:20:22 +0000</pubDate>
      <link>https://forem.com/gyi2521/mysql-vs-mongodb--5bj3</link>
      <guid>https://forem.com/gyi2521/mysql-vs-mongodb--5bj3</guid>
      <description>&lt;p&gt;Recently, I learned about MySQL from my Coding Boot Camp class in addition to MongoDB which has been the main database we used in the class. I wanted to share what I have learned so far about these two databases.&lt;/p&gt;

&lt;p&gt;The main difference is that MySQL uses structured query language (SQL) while MongoDB uses NoSQL. What is the difference between SQL and NoSQL? In one of the blogs I read, it used an analogy as living in a town where everyone speaks the same language vs. a town where people speak different languages.  &lt;/p&gt;

&lt;p&gt;SQL databases use structured query language (SQL) for defining and manipulating data. This is extremely powerful, but it can be restrictive. SQL requires that you use predefined schema to determine the structure of your data before you work with it. In addition, all your data must follow the same structure.&lt;/p&gt;

&lt;p&gt;A NoSQL database, on the other hand, has dynamic schema for unstructured data, and data is stored in many ways: it can be column-oriented, document-oriented, graph-based or organized as a Key Value store.&lt;/p&gt;

&lt;p&gt;MySQL is an extremely established database, meaning that there’s a huge community, extensive testing and quite a bit of stability. It is open source and free. It is available for all major platforms, including Linux, Windows, Mac, BSD and Solaris.&lt;/p&gt;

&lt;p&gt;MongoDB, on the other hand, is a non-relational database that stores data as ‘documents’ in a binary representation called BSON (Binary JSON).  It gives you flexibility to change your data schema without modifying any of your existing data. MongoDB is horizontally scalable, which helps reduce the workload and scale your business with ease. It is flexible, so you can add new columns or fields on MongoDB without affecting existing rows or application performance.&lt;/p&gt;

&lt;p&gt;I will wrap up with some query examples below.&lt;/p&gt;

&lt;pre&gt;
Select/Get statement:

MySQL: SELECT * FROM inventory
MongoDB: db.inventory.find({})

Insert/Post statement:

MySQL : INSERT INTO inventory (item_id, type) VALUES ('ab123', ‘electronics’)
MongoDB: db.inventory.create({item_id: ‘ab123’, type: ‘electronics’})
&lt;/pre&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>mysql</category>
      <category>mongodb</category>
    </item>
    <item>
      <title>API == server?</title>
      <dc:creator>gyi2521</dc:creator>
      <pubDate>Thu, 08 Nov 2018 16:03:30 +0000</pubDate>
      <link>https://forem.com/gyi2521/api--server-2plg</link>
      <guid>https://forem.com/gyi2521/api--server-2plg</guid>
      <description>&lt;p&gt;Recently, I ran into a YouTube video explaining API. The video used 'API is like a server in a restaurant' as an analogy, so I wanted to share that analogy here on my blog.&lt;/p&gt;

&lt;p&gt;Have you ever wondered exactly how we get all the information that we ask for on internet?  How we make a reservation or buy things with just a few clicks? The behind scene hero is API. It stands for Application Programming Interface.  &lt;/p&gt;

&lt;p&gt;API is the messenger that takes requests from us and tells a system what we want, and then returns the responses back to us, just like a server in a restaurant.  We, the customers, order food from a menu to a server, and the server takes the order to the kitchen and then brings back what we ordered to the table. &lt;/p&gt;

&lt;p&gt;If we apply this to a code, it will be like this:&lt;/p&gt;

&lt;pre&gt;
    //api call - ordering food
     $.get('/api/order')
       .then(function (food) {
           `put on the table`;
     });


    //api - server taking order
    app.get('/api/order', function (req, res) {
        `make food`(kitchen)
        return food;
    });
&lt;/pre&gt;

&lt;p&gt;Have you ever booked your flight using an online travel service?  It's similar to ordering food in a sit down restaurant. We enter our desired criteria for our travel (like food order) on the travel service website, and then the travel service website calls available airlines' API (like a server) to search for the flight information that matches our criteria from their system (like kitchen). Once the matching flight information are found, API returns the information  (like delivering food) back to the online travel service via response. The travel service website displays the flight information for us to compare and choose the best option.&lt;/p&gt;

&lt;p&gt;So the next time you think of an API, just think of it as your server running back and forth between applications, databases, and devices to deliver data and fulfill your request.&lt;/p&gt;

&lt;p&gt;By the way, I was once an API... back in college days... and it helped me pay my tuition...:-)&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>api</category>
    </item>
    <item>
      <title>AJAX - GET, POST, PUT,and DELETE</title>
      <dc:creator>gyi2521</dc:creator>
      <pubDate>Thu, 01 Nov 2018 20:06:53 +0000</pubDate>
      <link>https://forem.com/gyi2521/ajax---get-post-putand-delete--m9j</link>
      <guid>https://forem.com/gyi2521/ajax---get-post-putand-delete--m9j</guid>
      <description>&lt;p&gt;Hi everyone, I've been thinking about writing on how to make AJAX call immediately after I wrote the blog, "What is AJAX" [&lt;a href="https://dev.to/gyi2521/what-is-ajax-34c2"&gt;https://dev.to/gyi2521/what-is-ajax-34c2&lt;/a&gt;], about a month ago; however, I've been busy with my first group project, "InstagramClone", from my Boot-camp class, so here I am..  writing the second part of AJAX a month later..;)&lt;br&gt;
Good thing is that I can use the AJAX call examples from my project.&lt;/p&gt;

&lt;p&gt;In our "InstagramClone" project, we used jQuery's AJAX "GET" method on the client side to retrieve photos from the back-end. &lt;/p&gt;

&lt;pre&gt;
 $.ajax({ url: 'api/photos', method: 'GET' })
            .then(function (data) {
                let content = '';
                if (data != '') {
                   data.forEach(e =&amp;gt; {
                   content += `some code`;
 code continues...
&lt;/pre&gt;

&lt;p&gt;Our GET method starts with '$.ajax' followed by an object with two properties which are url and method. The Url field is populated with the API address that will provide the desired data from the back-end and the method field is populated with 'GET'. The next line, '.then(function(data))' is the process that executes once the data has been retrieved from the ajax call. In our case, we iterated through the data and displayed the photos on the screen.&lt;/p&gt;

&lt;p&gt;Now, lets look at AJAX POST(=create new) method. The following is the code we used to add a comment to a photo.&lt;/p&gt;

&lt;pre&gt;
$.ajax({ url: '/api/comments', method: 'POST', data:allComment})
            .then(function () {
                $(`#${photoid}_divForComments`).append($(`            
                &lt;b&gt;Instagram_Clone&lt;/b&gt; ${theComment}`));
            });
&lt;/pre&gt;

&lt;p&gt;The code is similar to GET method but we populated "POST" for the method field and also added the data that contains newly created user comment.&lt;/p&gt;

&lt;p&gt;The PUT(=update) method, is really identical to POST method as you can see below: &lt;/p&gt;

&lt;pre&gt;
$.ajax({ url: '/api/comments', method: 'PUT', data:likes})
            .then(function() {
                some code...
            });
&lt;/pre&gt;

&lt;p&gt;For the DELETE method, we are passing in photoId to delete. &lt;/p&gt;

&lt;pre&gt;
        $.ajax({ url: `/api/photo/${$(this).attr('photoId')}`, method: "DELETE" })
            .then(function (data) {
                some code...
            })
            .catch(function (err) {
                some code...
            });
&lt;/pre&gt;

&lt;p&gt;In above example, we just added '.catch(function (err)' to get the error message if there is any, and you can add this to all other calls as well.&lt;/p&gt;

&lt;p&gt;With AJAX, we can simply update the parts of a web page without reloading the whole page, and this makes the process much faster and responsive for users.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>ajax</category>
      <category>javascript</category>
    </item>
    <item>
      <title>What is Ajax?</title>
      <dc:creator>gyi2521</dc:creator>
      <pubDate>Tue, 25 Sep 2018 20:36:32 +0000</pubDate>
      <link>https://forem.com/gyi2521/what-is-ajax-34c2</link>
      <guid>https://forem.com/gyi2521/what-is-ajax-34c2</guid>
      <description>&lt;p&gt;What is Ajax?&lt;/p&gt;

&lt;p&gt;When the instructor asked "What is Ajax" in my coding boot-camp class, someone immediately answered, "A cleaning solution!".  We all laughed but that's how people will answer outside the computer world.  So, what is Ajax in the computer world? &lt;/p&gt;

&lt;p&gt;AJAX stands for Asynchronous JavaScript and XML. It is a web development technique for creating interactive web applications. AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This means that it is possible to update parts of a web page without reloading the whole page.&lt;/p&gt;

&lt;p&gt;A great example would be the Google suggestion list you see in the Google search box. When you start typing something in the Google search box, the list in that drop-down box changes. The content on the page dynamically changes without refreshing the page. How cool!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ebAlB6I7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/2t54lkf8pujkui7aknnc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ebAlB6I7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/2t54lkf8pujkui7aknnc.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So how does Ajax actually works? I got the following diagram and steps from w3schools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fIBFPBvJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/r3vai97x0f4zockefp0y.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fIBFPBvJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/r3vai97x0f4zockefp0y.gif" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How AJAX Works&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An event occurs in a web page (the page is loaded, a button is clicked)&lt;/li&gt;
&lt;li&gt;An HTTP Request object is created by JavaScript&lt;/li&gt;
&lt;li&gt;The HTTP Request object sends a request to a web server&lt;/li&gt;
&lt;li&gt;The server processes the request&lt;/li&gt;
&lt;li&gt;The server sends a response back to the web page &lt;/li&gt;
&lt;li&gt;The response is read by JavaScript&lt;/li&gt;
&lt;li&gt;Proper action (like page update) is performed by JavaScript&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I will explain how to create, add, update, and delete in my next blog, so stay tuned.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>ajax</category>
    </item>
    <item>
      <title>What is IIFE in JavaScript?</title>
      <dc:creator>gyi2521</dc:creator>
      <pubDate>Sat, 15 Sep 2018 13:18:11 +0000</pubDate>
      <link>https://forem.com/gyi2521/what-is-iife-in-javascript-o81</link>
      <guid>https://forem.com/gyi2521/what-is-iife-in-javascript-o81</guid>
      <description>&lt;p&gt;The first time I heard 'IIFE' in my Coding Bootcamp class, it immediately reminded me of my sister's dog 'Yeffi' which means 'pretty' in some human language.&lt;/p&gt;

&lt;p&gt;So what is IIFE in JavaScript language?&lt;/p&gt;

&lt;p&gt;IIFE stands for Immediately Invoked Function Expression. It is a JavaScript function that runs as soon as it is defined.&lt;/p&gt;

&lt;p&gt;Normally, when we create a function using 'Function Declaration' or 'Function Expression', we need to call the function in order to use it.&lt;/p&gt;

&lt;pre&gt;
Function Declaration:

function myFunction(p1, p2) {
    return p1 * p2;
}
alert(myFunction(4, 3));
//12

Function Expression:

let myFunction = function(p1, p2){
    return p1 * p2;
}
alert(myFunction(4,3));
//12

&lt;/pre&gt; 

&lt;p&gt;However, in IIFE, the function is wrapped in a parenthesis which makes it a function expression followed by () which tells the JavasScript compiler to invoke or call immediately.&lt;/p&gt;

&lt;pre&gt;(function() {
   let dName = "Yeffi";
   alert(dName);
}
)();
//Yeffi
&lt;/pre&gt;

&lt;p&gt;So why do we use IIFE?&lt;/p&gt;

&lt;p&gt;Mainly because of privacy. Any variables declared inside the IIFE are not accessible from the outside world.&lt;/p&gt;

&lt;pre&gt;
(function() {
   let dName = "Yeffi";
}
)();

console.log(dName);
//  Uncaught ReferenceError: dName is not defined
&lt;/pre&gt;

&lt;p&gt;If you try to access the dName variable outside of the IIFE, you get the error message as you can see above. All the variables inside the IIFE stay within the scope of the function.&lt;br&gt;
Also, it protects the global namespace by not creating a named function. When a named function lingers in the global namespace, it could accidentally be called again. However, since IIFE isn't a named function, it can't accidentally be called. This will avoid any potential security implications. Therefore, many JavaScript libraries use this technique nowadays.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
