<?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: Bethany Jones</title>
    <description>The latest articles on DEV Community by Bethany Jones (@bethanyjones).</description>
    <link>https://dev.to/bethanyjones</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%2F845928%2F50d033fc-d591-44ef-81a3-b126b70a6fee.jpeg</url>
      <title>DEV Community: Bethany Jones</title>
      <link>https://dev.to/bethanyjones</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bethanyjones"/>
    <language>en</language>
    <item>
      <title>Common AngularJS Directives</title>
      <dc:creator>Bethany Jones</dc:creator>
      <pubDate>Mon, 13 Jun 2022 00:24:45 +0000</pubDate>
      <link>https://dev.to/bethanyjones/common-angularjs-directives-1of7</link>
      <guid>https://dev.to/bethanyjones/common-angularjs-directives-1of7</guid>
      <description>&lt;p&gt;One of the main criticisms of HTML and CSS is that it is static with very little interactivity. Web and app users these days expect to be able to dynamically change elements on a page with a click of a button and seamlessly transition between sections of the site or app. Additionally, many web applications are built as Single-Page-Applications (SPA) and/or use Model-View-Controller (MVC) architecture. All of that can be difficult to achieve with pure HTML, CSS, jQuery, and even JavaScript. Thankfully, there are libraries and frameworks that help address this issue, one in particular being AngularJS (&lt;a href="https://www.geeksforgeeks.org/difference-between-angular-and-angularjs/"&gt;not to be confused&lt;/a&gt; with Angular).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MVC &amp;amp; AngularJS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AngularJS uses a MVC approach to build single page apps. If you’re unclear on what MVC actually is, FreeCodeCamp’s &lt;a href="https://www.freecodecamp.org/news/simplified-explanation-to-mvc-5d307796df30/"&gt;sandwich metaphor&lt;/a&gt; might help clarify the concept. Essentially MVC architecture splits up your application into the model (data), the controllers (the middle man between the user and the system), and the views (the user interface/frontend that the user sees). While I won’t delve too deep into the &lt;a href="https://www.geeksforgeeks.org/benefit-of-using-mvc/"&gt;benefits&lt;/a&gt; of MVC architecture, suffice it to say that AngularJS operates on a similar logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AngularJS Directives&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The documentation refers to AngularJS as a “structural framework for dynamic web apps”(&lt;em&gt;“What Is AngularJS?” AngularJS.Org&lt;/em&gt;). It expands the current HTML syntax through the use of directives that teach the browser new behaviors. It does this by adding new Directive attributes to DOM elements. &lt;/p&gt;

&lt;p&gt;AngularJS has both pre-made directives and also allows us to create custom ones as well. While there are some 67+ &lt;a href="https://docs.angularjs.org/api/ng/directive"&gt;directives &lt;/a&gt;listed on the AngularJS site, we’ll be going over some of the more common ones and breaking down the syntax and how to use them in your own projects. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D-At3tlK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9d8xm0wnvago58mshv79.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D-At3tlK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9d8xm0wnvago58mshv79.gif" alt="Image description" width="820" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;br&gt;
&amp;lt;html lang="en" ng-app&amp;gt;&lt;br&gt;
&amp;lt;head&amp;gt;&lt;br&gt;
    &amp;lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;
    &amp;lt;title&amp;gt;Learning AngularJS Directives&amp;lt;/title&amp;gt;&lt;br&gt;
&amp;lt;/head&amp;gt;&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
    &amp;lt;h2&amp;gt;Learning AngularJS Directives&amp;lt;/h2&amp;gt;&lt;br&gt;
    &amp;lt;h5&amp;gt;AngularJS in Action&amp;lt;/h5&amp;gt;&lt;br&gt;
    &amp;lt;p&amp;gt;With just a few extra snippets of code, we can turn a  &lt;br&gt;
static input form into something dynamic.&amp;lt;/p&amp;gt;&lt;br&gt;
    &amp;lt;input type="text" ng-model="myName" placeholder="enter your name" /&amp;gt;&lt;br&gt;
    &amp;lt;h5&amp;gt;Hello {{myName}}&amp;lt;/h5&amp;gt;&lt;br&gt;
    &amp;lt;p&amp;gt;Thank you for joining us today on our journey through AngularJS.&amp;lt;/p&amp;gt;&lt;br&gt;
&amp;lt;/body&amp;gt;&lt;br&gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Some bootstrap code was removed for brevity and illustration purposes.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The above is a simple illustration of how easily we can incorporate dynamic elements in our applications. With just a few AngularJS directives (and a bit of Bootstrap), we were able to take a standard HTML form input and capture the values as they were typed and render them on the page in real time. Pretty nifty, right? Just wait until you see what else AngularJS can do.&lt;/p&gt;

&lt;h3&gt;
  
  
  Attribute Directives Syntax
&lt;/h3&gt;

&lt;p&gt;Attribute directives are prefixed with &lt;code&gt;ng-&lt;/code&gt; followed by the name of the attribute. These directives are used alongside other HTML attributes. Some common ones you’ll see covered here and elsewhere are &lt;code&gt;ng-app&lt;/code&gt;, &lt;code&gt;ng-click&lt;/code&gt;, &lt;code&gt;ng-model&lt;/code&gt;, among others.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data Binding Expressions
&lt;/h3&gt;

&lt;p&gt;Similar to how JavaScript uses embedded &lt;code&gt;${expressions}&lt;/code&gt; as placeholders for data and can be used inside of HTML, so, too, does AngularJS. With AngularJS, we simply add an extra pair of curly braces: &lt;code&gt;{{myName}}&lt;/code&gt;. Not only are we able to swap in data, we can also evaluate the expressions on the fly like you would in JavaScript. &lt;code&gt;{{5 + 5}}&lt;/code&gt; would resolve to 10 and that would be what is displayed for the viewer.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Common Directives
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;ng-app&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
In the above example, we initialize the AngularJS app with a &lt;code&gt;ng-app&lt;/code&gt; directive in the HTML lang tag, like so: &lt;code&gt;&amp;lt;html lang="en" ng-app&amp;gt;&lt;/code&gt;. The ng-app designates the root element of the app allowing us to incorporate further directives throughout the code and using AngularJS as soon as the page is loaded. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;ng-model&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
The ng-model directive is used to bind HTML form elements to a variable in the scope. This directive is only supported by &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt; elements. So, in the context of our example, we used the directive ng-model with a property name of "myName"  to bind the value created by the input field to the &lt;code&gt;{{myName}}&lt;/code&gt; expression used later in the code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;input type="text" ng-model="myName" placeholder="enter your name" /&amp;gt;&lt;/code&gt;&lt;br&gt;
…&lt;br&gt;
&lt;code&gt;&amp;lt;h5&amp;gt;Hello {{myName}}&amp;lt;/h5&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It was this directive that allowed the text to be displayed in the browser in real time as it was typed into the input field. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;ng-init&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
This directive is used as a way to define some initial data, be it an array of names, a primitive value, or an object of key-value pairs. It is useful for demonstrating AngularJS’ capabilities as it allows us to see HTML elements change based on how we manipulate the initial data found in &lt;code&gt;ng-init&lt;/code&gt;. However, more often than not, you will be using controllers or modules in the backend to do this instead. For now, let’s see &lt;code&gt;ng-init&lt;/code&gt; in use. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div ng-init="arrayName=['cats', 'dogs']"&amp;gt;&lt;br&gt;
    &amp;lt;p&amp;gt;It is raining {{arrayName[0]}} and {{arrayName[1]}}.&amp;lt;/p&amp;gt;&lt;br&gt;
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This code would display on the page as “It is raining cats and dogs.” &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;ng-repeat&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
Probably one of the more useful directives, &lt;code&gt;ng-repeat&lt;/code&gt; lets you repeat lines of code without actually having to repeat lines of code. No more hard-coding &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; elements! It will render a set of HTML a given number of times, but can only be used on objects or arrays. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div ng-init="array=[‘Birds’, 2, 100, ‘lions’, ‘pizza’]"&amp;gt;&lt;br&gt;
    &amp;lt;li ng-repeat="element in array"&amp;gt;{{element}}&amp;lt;/li&amp;gt;&lt;br&gt;
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So, as we can see here, we use the &lt;code&gt;ng-repeat&lt;/code&gt; directive in the element we want to see repeated, in this case a list item. We connect the directive to the data by using an arbitrary variable name (&lt;code&gt;element&lt;/code&gt;), the keyword in, and most importantly the name of the array or object we want to iterate through (&lt;code&gt;array&lt;/code&gt;), giving us &lt;code&gt;ng-repeat="element in array"&lt;/code&gt;. Then we use that same variable name in an expression (&lt;code&gt;{{element}}&lt;/code&gt;) located where we want the data to appear. The directive will loop through the array or object until all elements have been rendered. And like magic, we will have a list of these array elements on the page.&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;**ng-click**&lt;/code&gt;&lt;br&gt;
The last directive we will cover is the &lt;code&gt;ng-click&lt;/code&gt; directive. Gone are the days of assigning clunky event listeners to key elements on your app. With the &lt;code&gt;ng-click&lt;/code&gt; directive we can place it directly on any element we want to monitor for clicks. For example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;h1 class="smiley"&amp;gt;{{count}}&amp;lt;/h1&amp;gt;&lt;br&gt;
&amp;lt;button ng-click="count = count + '😄'" ng-init="count='😄'"&amp;gt;Smile&amp;lt;/button&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jfKQWcqz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y9nk2pmsvjd7v1o3y7yf.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jfKQWcqz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y9nk2pmsvjd7v1o3y7yf.gif" alt="Image description" width="794" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We used &lt;code&gt;ng-init&lt;/code&gt; directive to set the initial value of count to &lt;code&gt;😄&lt;/code&gt;. Everytime there is a click on the button, the &lt;code&gt;ng-click&lt;/code&gt; directive is evaluating the expression &lt;code&gt;count = count + '😄'&lt;/code&gt; which is simply adding a &lt;code&gt;😄&lt;/code&gt; to the variable &lt;code&gt;count&lt;/code&gt; and reassigning the result to &lt;code&gt;count&lt;/code&gt;. That then updates the &lt;code&gt;{{count}}&lt;/code&gt; expression in the &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; tag showing us the parade of emojis marching across the screen upon each button click. &lt;/p&gt;

&lt;p&gt;There are dozens of other useful and powerful AngularJS directives for you to explore in more depth. To that end, here are some handy &lt;a href="https://cheatography.com/proloser/cheat-sheets/angularjs/"&gt;cheatsheets&lt;/a&gt; and &lt;a href="https://www.airpair.com/angularjs"&gt;guides&lt;/a&gt; to help you deepen your understanding of this framework. Happy coding out there.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>angular</category>
      <category>html</category>
    </item>
    <item>
      <title>Understanding JavaScript Data Types (Through the Lens of D&amp;D &amp; Other TTRPGs)</title>
      <dc:creator>Bethany Jones</dc:creator>
      <pubDate>Sun, 17 Apr 2022 22:35:57 +0000</pubDate>
      <link>https://dev.to/bethanyjones/understanding-javascript-data-types-through-the-lens-of-dd-other-ttrpgs-399h</link>
      <guid>https://dev.to/bethanyjones/understanding-javascript-data-types-through-the-lens-of-dd-other-ttrpgs-399h</guid>
      <description>&lt;p&gt;Humans &lt;em&gt;love&lt;/em&gt; to make sense of our world and ourselves through categorization; whether it's understanding biological life through taxonomy, ourselves through identity labels, or even our fictional RPG characters through their "classes," we want to break things down into their smallest components and group them based on certain characteristics and similarities. Computer programming, and JavaScript in particular, is no different. &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;What Are Data Types &amp;amp; Why We Need Them&lt;/strong&gt;&lt;br&gt;
Just as the Dungeon &amp;amp; Dragons RPG system has a set of rules that governs how the different character classes behave, programming languages have a type system that classifies how the built-in data structures should behave depending on their "type." &lt;/p&gt;

&lt;p&gt;As Aaron Krauss describes it in his &lt;a href="https://thecodeboss.dev/2015/11/programming-concepts-static-vs-dynamic-type-checking/"&gt;blog&lt;/a&gt; "Programming Concepts: Static Vs. Dynamic Type Checking":&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A type system is a collection of rules that assign a property called type to various constructs in a computer program, such as variables, expressions, functions or modules, with the end goal of reducing the number of bugs by verifying that data is represented properly throughout a program.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words, data types refers to the 'type' of value we're working with. It's a way to categorize the information/data that we use so that we interact with our code appropriately. &lt;/p&gt;

&lt;p&gt;Every value is associated with a certain data type that falls into one of these *main categories: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number&lt;/li&gt;
&lt;li&gt;String &lt;/li&gt;
&lt;li&gt;Boolean &lt;/li&gt;
&lt;li&gt;Array &lt;/li&gt;
&lt;li&gt;Object &lt;/li&gt;
&lt;li&gt;Function &lt;/li&gt;
&lt;li&gt;undefined &lt;/li&gt;
&lt;li&gt;null&lt;/li&gt;
&lt;li&gt;NaN
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let partyMembers = 9; // Number
let partyName = 'The Fellowship'; // String
let allSurvive = false; // Boolean

// Array
let partyMemberAges = [87, 38, 2000, 50, 2000, 28, 36, 139, 40]; 

// Object
let partyClasses = {
Aragorn: 'Fighter',
Sam: 'Paladin',
Gandalf: 'Wizard',
Frodo: 'NPC',
Legolas: 'Fighter',
Pippin: 'Rogue',
Merry: 'Bard',
Gimli: 'Fighter',
Boromir: 'Fighter'
}

//Function
function averagePartyAge(array){
let totalAge = 0;
for(var i = 0; i &amp;lt; array.length; i++){
totalAge += array[i];
}
return totalAge / array.length;
}

let bestMember; // undefined
let worstMember = null; // null
let middleEarth = partyName * allSurvive; // NaN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;These data types have various properties and methods associated with them that allow the JavaScript interpreter to correctly handle this data. For example, the interpreter treats numbers differently from strings, so while &lt;code&gt;2 + 2&lt;/code&gt; and &lt;code&gt;'2' + '2'&lt;/code&gt; look very similar, they are actually different data types: Numbers and Strings, respectively. Without understanding their type, the interpreter would not be able to execute this code correctly. So, now that you know &lt;em&gt;why&lt;/em&gt; we need these data types, let's talk about each of the data types in turn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Number&lt;/strong&gt;&lt;br&gt;
The Number data type represents all numeric values (both positive and negative). Categorizing these numeric values as Numbers allows us to use the static properties and methods attached to that data type. We are also able to perform calculations on Number data types by using arithmetic operations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let currentXP = 6; // resolves to the number 6
let previousXP = 1000; // resolves to 1000
let totalXP = currentXP + previousXP; // resolves to 1006
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;currentXP&lt;/code&gt; and &lt;code&gt;previousXP&lt;/code&gt; are Number data types because they have a numeric value and are not written as strings, which means we are able to add these values together. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;String&lt;/strong&gt;&lt;br&gt;
The String data type is a collection of characters between either single or double quotes. Strings allow us to represent data in text form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let moreExperience = 'Your character gets 500 more xp!'; 
let xpUpdate = '500'; // resolves to a string of '500' 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The variables &lt;code&gt;moreExperience&lt;/code&gt; and &lt;code&gt;xpUpdate&lt;/code&gt; are strings, despite also having numbers in them. If you were to try and add &lt;code&gt;xpUpdate + currentXP&lt;/code&gt;, the JavaScript interpreter would type coerce &lt;code&gt;currentXP&lt;/code&gt; as string rather than adding the values together to create a sum. So, instead of outputting 506 as you might expect, it would concatenate these values as a string and return 5006.&lt;/p&gt;

&lt;p&gt;Arithmetic operations cannot be used on this variable unless it is first converted to the number data type. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Boolean&lt;/strong&gt;&lt;br&gt;
Booleans hold only one of two values: true or false. Booleans are most useful when storing values with clear binaries, such as yes/no or on/off. When only one of two values are possible, Booleans are usually used.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let haveSpellSlots = true;
let spellsCount = 0;
if(spellsCount &amp;lt;= 0){ 
haveSpellSlots = false; // change to a Boolean of false
}
console.log(haveSpellSlots); // prints =&amp;gt; false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The variable &lt;code&gt;haveSpellSlots&lt;/code&gt; is assigned to the Boolean &lt;code&gt;true&lt;/code&gt;, denoting that yes, we have spell slots available to use. If the value of &lt;code&gt;spellsCount&lt;/code&gt; is less than or equal to 0, however, the &lt;code&gt;haveSpellSlots&lt;/code&gt; is reassigned to a Boolean of &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array&lt;/strong&gt;&lt;br&gt;
The array data type categorizes objects that can store a collection of items in an indexed list. These data types can be expanded, and thus are also considered complex data types. Arrays are denoted by the use of &lt;code&gt;[brackets]&lt;/code&gt; when assigned a variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let characterTraits = ['1', 5, [], true, 'Adora', 'Druid']; 
console.log(typeof(characterTraits)); // prints =&amp;gt; 'object'
console.log(Array.isArray(characterTraits)); // prints =&amp;gt; true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The variable &lt;code&gt;characterTraits&lt;/code&gt; is assigned to an array containing 6 elements. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Object&lt;/strong&gt;&lt;br&gt;
The object data type is used for storing a collection of keyed data and other data types (like functions). Essentially objects are variables that can store a multitude of values. Like arrays, objects are also considered a complex data type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const dndCharacter = {
    class: 'Druid',
    level: 1,
    cantrips: ['Guidance', 'Mending', 'Shillelagh'],
    lvlSpells: ['Cure Wounds', 'Healing Word'],
    haveSpells: false,
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above &lt;code&gt;dndCharacter&lt;/code&gt; object has keys of &lt;code&gt;class&lt;/code&gt;, &lt;code&gt;level&lt;/code&gt;, &lt;code&gt;cantrips&lt;/code&gt;, &lt;code&gt;lvlSpells&lt;/code&gt;, and &lt;code&gt;haveSpells&lt;/code&gt;, each of these containing different types of values. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function&lt;/strong&gt;&lt;br&gt;
The function data types denote a block of statements that perform some task or calculation. Functions are a complex data type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function whoIsDM(name){
console.log(`${name} is the Dungeon Master`);
}

whoIsDM('Chris'); // calls the function

'Chris is the Dungeon Master' // logged to the console
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;undefined&lt;/strong&gt;&lt;br&gt;
The undefined data type represents undefined values or values that have not been initialized.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let nextCampaign; 
console.log(nextCampaign); // prints =&amp;gt; undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;nextCampaign&lt;/code&gt; variable is declared, but has not been assigned to any value, thus when it is later called, it returns undefined. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;null&lt;/strong&gt;&lt;br&gt;
The null data type represents none or the absence of value. These occur when the programmer intentionally initializes a piece of data to null.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let empty = null; // assigned a variable to null
console.log(empty); // prints =&amp;gt; null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NaN&lt;/strong&gt;&lt;br&gt;
NaN is a special number type that stands for Not-A-Number. NaN happens when an arithmetic operation is applied to a invalid or undefined value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log('Do not split the party!' / 9); // prints =&amp;gt; NaN 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Primitive vs. Complex Data Types&lt;/strong&gt;&lt;br&gt;
In addition to the above categories, cata can can also be classified as either primitive/simple or complex data types. We can use the typeof operator to help us determine what type a piece of data is. &lt;/p&gt;

&lt;p&gt;Primitive/Simple data types include: Numbers, Strings, Booleans, NaNs, undefined, and null. These data types are considered simple because they are atomic and immutable, which means they do not aggregate other values (like arrays and objects). &lt;/p&gt;

&lt;p&gt;Also, simple data types are copy by value meaning that any code that acts on these data types would simply be working with a copy of the original, rather than modifying the original value itself.&lt;/p&gt;

&lt;p&gt;So, manipulating a primitive data type would result in an entirely new simple value. Variables can hold the actual values of primitive types, but this necessitates that simple data types be a fixed size. &lt;/p&gt;

&lt;p&gt;Complex data types include: Objects, Arrays, and Functions. Unlike simple data types, complex data types can collect and add to the values contained within. These data types are store as a reference, meaning that we can act directly upon the original, thus changing it. Because complex data types can be added to and manipulated, they have an indefinite size.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let characterName = 'Adora'; 
let druidName = 'Adora';  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The variable &lt;code&gt;characterName&lt;/code&gt; is a simple data type with a string. The value 'Adora' cannot be mutated or altered directly. &lt;code&gt;druidName&lt;/code&gt; is an entirely new variable with a new value with no relationship to the above variable. Because strings are immutable, you cannot use methods to alter the original. You can see this demonstrated below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;druidName.toUpperCase(); // nothing happens
console.log(druidName); // prints =&amp;gt; 'Adora'
druidName = 'Adora Mossweather'; // reassigned
console.log(druidName); // prints =&amp;gt; 'Adora Mossweather'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing happens to &lt;code&gt;druidName&lt;/code&gt; as it cannot be directly altered with these methods. However, variables &lt;em&gt;can&lt;/em&gt; be reassigned, as shown by the variable &lt;code&gt;druidName&lt;/code&gt; which has taken on a new value.&lt;/p&gt;

&lt;p&gt;Unlike Strings, Numbers, and Booleans, Objects &lt;em&gt;can&lt;/em&gt; be mutated by using an object method on the original. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const dndCharacter = {
    class: 'Druid',
    level: 1,
    cantrips: ['Guidance', 'Mending', 'Shillelagh'],
    lvlSpells: ['Cure Wounds', 'Healing Word'],
    haveSpells: false,
}

dndCharacter.name = druidName; // adds druidName property 
console.log(dndCharacter); // prints =&amp;gt; updated object
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because &lt;code&gt;dndCharacter&lt;/code&gt; is an object, we are able to include a new property called &lt;code&gt;name&lt;/code&gt; with the &lt;code&gt;druidName&lt;/code&gt; as its value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Copy by Value vs Copy by Reference&lt;/strong&gt;&lt;br&gt;
All primitive data values are copied by value, while all complex data types are copied by reference. What that means is a variable can reference another variable, but the value stored is merely a replica of the original, as demonstrated below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;characterName = druidName; // points to a copy of druidName
console.log(characterName); // prints =&amp;gt; 'Adora Mossweather'

characterName = 'Adoria Mossy'; // reassigns to a new value

console.log(druidName); // prints =&amp;gt; 'Adora Mossweather'
this variable was not affected by the above variable's reassignment

console.log(characterName); // prints =&amp;gt; 'Adoria Mossy'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;druidName&lt;/code&gt; variable was not affected by the &lt;code&gt;characterName&lt;/code&gt; variable's reassignment.&lt;/p&gt;

&lt;p&gt;Complex data types, however, are copied by reference which means that the original object, array, or function can be modified directly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dndCharacter.lvlSpells.push('Barkskin', 'Flaming Sphere', 'Moonbeam'); 
// adds 3 more elements to the spells array located in the dndCharacter object


console.log(dndCharacter); // prints =&amp;gt; object with the values

{
  class: 'Druid',
  level: 1,
  cantrips: [ 'Guidance', 'Mending', 'Shillelagh' ],
  lvlSpells: [
    'Cure Wounds',
    'Healing Word',
    'Barkskin',
    'Flaming Sphere',
    'Moonbeam'
  ],
  haveSpells: false,
  name: 'Adora Mossweather'
}

let dndParty = dndCharacter;
console.log(dndParty); // prints =&amp;gt; same object as dndCharacter

dndParty.companions = ['Percy', 'Roark', 'Vox']; 
console.log(dndCharacter.companions); // prints =&amp;gt; array

dndParty = {};
console.log(dndParty); // prints =&amp;gt; {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The variable &lt;code&gt;dndParty&lt;/code&gt; points directly to the same object as the variable &lt;code&gt;dndCharacter&lt;/code&gt;. Because of copy by reference, when we add a new key property to &lt;code&gt;dndParty&lt;/code&gt;, &lt;code&gt;dndCharacter&lt;/code&gt; is updated as well. It is only when we reassign &lt;code&gt;dndParty&lt;/code&gt; to a new empty object that it is no longer referencing the object stored at &lt;code&gt;dndCharacter&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And, that, in a nutshell is what JavaScript data types are and how you can identify them in your own code. &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;BigInt and Symbols are also a data type, but we will not be touching on those in this article.&lt;/em&gt;&lt;/p&gt;

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