<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Loyd Kim on Medium]]></title>
        <description><![CDATA[Stories by Loyd Kim on Medium]]></description>
        <link>https://medium.com/@loydkim?source=rss-d2e5add59b62------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*468pGCGH0aF2q86SRTyO1w.jpeg</url>
            <title>Stories by Loyd Kim on Medium</title>
            <link>https://medium.com/@loydkim?source=rss-d2e5add59b62------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 20:29:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@loydkim/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Intro to JavaScript for Ruby and Non-Ruby Programmers: Objects & Data Types]]></title>
            <link>https://medium.com/@loydkim/intro-to-javascript-for-ruby-and-non-ruby-programmers-objects-data-types-3d18d3672516?source=rss-d2e5add59b62------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d18d3672516</guid>
            <category><![CDATA[education]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Loyd Kim]]></dc:creator>
            <pubDate>Wed, 20 Mar 2019 13:37:54 GMT</pubDate>
            <atom:updated>2019-03-20T13:47:49.089Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2VpRiJZ7JNoLUjFg" /><figcaption>Photo by <a href="https://unsplash.com/@goshua13?utm_source=medium&amp;utm_medium=referral">Joshua Aragon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you’re coming from a Ruby background, chances are, you’ve heard the phrase “everything is an object in Ruby”. This doesn’t hold quite true in JavaScript, and, before I move onto explaining why, I’m going to have to first explain what an object is in JavaScript.</p><h3>Objects in Ruby: A Quick Overview</h3><p>As you may know, objects in Ruby are considered to be instances of classes. For instance (no pun intended), if I have a <em>Dog</em> class, then a variable <em>digby</em> could be an object of that Dog class:</p><pre>class Dog  <br>  attr_reader :name  <br>  def initialize(name)    <br>    @name = name  <br>  end<br>end </pre><pre>digby = Dog.new(&quot;Digby&quot;) </pre><pre>p digby.name # =&gt; &quot;Digby&quot;</pre><p>We know that <em>digby</em> is an object of the <em>Dog</em> class because it’s using the <strong>.new</strong> class method, which instantiates a new instance object of an existing class.</p><h3>Objects in JavaScript</h3><p>In JavaScript, objects are nothing more than what hashes are in Ruby. In other words, <strong>JavaScript objects are simply key-value pairs</strong>. For instance, in the case of JavaScript, the above Ruby code would translate like this:</p><p><strong>NOTE</strong>: I’m using what’s called ES6 syntax here, which is, in short, an iteration of the standardized version of JavaScript. You can read more about ES6, and its cool features <a href="https://www.w3schools.com/js/js_es6.asp">here</a>. Now, why am I telling you this? Because there are many ways to define things like classes in JavaScript, but, it’s usually best practice to use the methods that are most familiar in the developer community!</p><pre>class Dog {<br>  constructor(name) {<br>    this.name = name;<br>  }<br>}</pre><pre>const digby = new Dog(&quot;Digby&quot;);</pre><pre>console.log(digby.name); // =&gt; &quot;Digby&quot;</pre><p>You can essentially think of <em>digby</em> as looking like this:</p><pre>{<br>  name: &quot;Digby&quot;<br>}</pre><p>And, just as a quick aside, if you don’t already know, you can <em>key</em> into key-value pairs via <strong>dot notation</strong>, which is what I used above, OR via <strong>bracket notation</strong>. So, this should give you the same output:</p><pre>console.log(digby[&quot;name&quot;]) // =&gt; &quot;Digby&quot;</pre><p><strong>Note</strong>: In JavaScript, unlike Ruby, you have to specify the key as a string when using bracket notation. For example, in Ruby, you could do something like:</p><pre>digby[name]</pre><pre># You can&#39;t actually do this in the context of the example above because, in Ruby, objects are not key-value pairs (not a hash).</pre><p>While in JavaScript, you’d need to specify “name” as a string, like I did above.</p><p>Alright, so that’s what objects are in JavaScript, in a nutshell. Phew, just one more section to go!</p><h3>JavaScript Data Types</h3><p>Remember how I said that not everything is an object in JavaScript many moons ago? Now that you’re equipped with the basic knowledge to understand the fundamental difference between Ruby and JavaScript &amp; what an object is in JavaScript, we’re ready to move onto the meat of our story!</p><p>The reason why everything is an object in Ruby is because everything, in Ruby, is an instance of some pre-existing or manually-created class. For instance, <em>digby</em> is an instance of the <em>Dog</em> class:</p><pre>p digby.class # =&gt; &quot;Dog&quot;</pre><p>However, because EVERYTHING is an object in Ruby, you even get something like this:</p><pre>p 1.class    # =&gt;&quot;Integer&quot;<br>p 1.1.class  # =&gt; &quot;Float&quot;</pre><p>The numbers 1 and 1.1 are instances of Ruby’s built-in Integer and Float classes, respectively. Awesome, huh? Well, that’s not quite the case with JavaScript (if only life were that simple, right?).</p><p>In JavaScript, we have what’s called <strong>data types</strong>, and they’re split into two categories:</p><ol><li>Primitive Data Types</li><li>Non-Primitive Data Types</li></ol><h4>Primitive Data Types</h4><p>Primitive data types are <strong><em>immutable</em></strong> data, which means that they CAN’T be manipulated. What you get is… well, what you get. Also, these are the data types that are NOT objects. Examples of primitive data types include:</p><ol><li>Integers</li><li>Strings</li><li>Booleans</li><li>Undefined</li><li>Null</li></ol><p><strong>Note</strong>: Unlike Ruby, ALL numbers, both Integers and Floats, are categorized as a “number”. You can check this by running:</p><pre>console.log(typeof 1);</pre><p>Also, what <em>nil</em> is to Ruby, <em>null</em> is to JavaScript.</p><p>Because primitive data types are not objects, that means that they don’t have their own built-in methods. So, while, in Ruby, you can do something like this:</p><pre>p -1.abs # =&gt; 1</pre><p>In JavaScript, you’d have to do this:</p><pre>console.log(Math.abs(-1)) // =&gt; 1</pre><pre>// There is NO .abs method built into a number in JavaScript because, again, it&#39;s NOT an object; it&#39;s a primitive data type.</pre><h4>Non-Primitive Data Types</h4><p>Non-primitive data types are, as you may have already guessed, objects. This means that they are:</p><ol><li>Some instance of either a built-in JavaScript class or a class created by you.</li><li>They DO have built-in methods.</li><li>They are essentially key-value pairs.</li></ol><p>An example of a non-primitive data type is like the Dog class we built earlier in this article! It’s as simple as that :)</p><h3>Conclusion</h3><p>All in all, this stuff may be really basic, but it’s extremely important nonetheless. Not knowing the difference between a primitive and a non-primitive data type in JavaScript could really make it or break it fer ya as a developer, so make sure you know the difference!</p><p>Also, thank you for taking the time to read this article! If you’ve made it this far, know that I’m very thankful from the bottom of my heart :’)</p><p>This is my first post, so I may have a lot of polishing to do, but I promise I’ll get better over time! In the meantime, I would appreciate some feedback, if you’re so willing. Otherwise, again, thanks for reading this article. Hopefully it was helpful for you. Until next time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d18d3672516" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>