<?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: dan crowley</title>
    <description>The latest articles on DEV Community by dan crowley (@danjpeg).</description>
    <link>https://dev.to/danjpeg</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%2F1060769%2Ffa8d8c96-a709-4f7c-b4d9-3da1f432ef53.png</url>
      <title>DEV Community: dan crowley</title>
      <link>https://dev.to/danjpeg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danjpeg"/>
    <language>en</language>
    <item>
      <title>Flask SQLAlchemy - Strengths and Weaknesses</title>
      <dc:creator>dan crowley</dc:creator>
      <pubDate>Thu, 20 Jul 2023 02:45:03 +0000</pubDate>
      <link>https://dev.to/danjpeg/flask-sqlalchemy-strengths-and-weaknesses-940</link>
      <guid>https://dev.to/danjpeg/flask-sqlalchemy-strengths-and-weaknesses-940</guid>
      <description>&lt;h2&gt;
  
  
  flask sqlalchemy: strengths and weaknesses
&lt;/h2&gt;

&lt;p&gt;Flask SQLAlchemy is a powerful extension for the Flask web framework that provides a convenient way to work with databases using SQLAlchemy, a popular ORM library for python. It allows developers to interact with databases using Python classes instead of writing raw SQL queries, which makes can streamlines interactions with the database. Let's look at some of its strengths and weaknesses, and cover some use cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  strengths:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  integration with flask
&lt;/h3&gt;

&lt;p&gt;Flask SQLAlchemy is designed to work seamlessly with Flask, making it easy to incorporate database functionality into Flask applications. It leverages Flask's flexible architecture, allowing developers to build scalable and modular applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  pythonic syntax
&lt;/h3&gt;

&lt;p&gt;Flask SQLAlchemy embraces Python's philosophy, making it more intuitive for Python developers. It allows them to define models and perform database operations using familiar Python syntax, which enhances productivity.&lt;/p&gt;

&lt;h3&gt;
  
  
  orm flexibility
&lt;/h3&gt;

&lt;p&gt;SQLAlchemy, the underlying ORM library, provides a high level of abstraction and supports multiple database backends. Flask SQLAlchemy inherits these features, allowing developers to switch between different database engines without significant code changes.&lt;/p&gt;

&lt;h3&gt;
  
  
  query generation
&lt;/h3&gt;

&lt;p&gt;It offers a robust query generation system that enables developers to build complex database queries using Pythonic expressions, enhancing code readability and maintainability.&lt;/p&gt;

&lt;h3&gt;
  
  
  testability
&lt;/h3&gt;

&lt;p&gt;Flask SQLAlchemy facilitates unit testing by allowing developers to create test databases and test data within the application context. This ensures better isolation and accurate testing of database-related code.&lt;/p&gt;

&lt;h2&gt;
  
  
  weaknesses:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  learning curve
&lt;/h3&gt;

&lt;p&gt;For developers new to Flask or SQLAlchemy, the learning curve can be steep. Understanding the concepts of both Flask and SQLAlchemy takes time and practice, which might deter some beginners.&lt;/p&gt;

&lt;h3&gt;
  
  
  boilerplate code
&lt;/h3&gt;

&lt;p&gt;While Flask SQLAlchemy abstracts many database operations, developers may still need to write boilerplate code for common tasks, such as session handling and query execution.&lt;/p&gt;

&lt;h3&gt;
  
  
  performance overhead
&lt;/h3&gt;

&lt;p&gt;The additional layer of abstraction introduced by SQLAlchemy can lead to a slight performance overhead compared to raw SQL queries, especially for complex and high-volume database operations.&lt;/p&gt;

&lt;h3&gt;
  
  
  limited advanced features
&lt;/h3&gt;

&lt;p&gt;While SQLAlchemy is a powerful ORM, some advanced features and optimizations available in standalone SQLAlchemy might not be directly accessible or well-documented in Flask SQLAlchemy.&lt;/p&gt;

&lt;p&gt;comparison with django and ruby on rails:&lt;/p&gt;

&lt;h1&gt;
  
  
  django:
&lt;/h1&gt;

&lt;h2&gt;
  
  
  strengths:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  comprehensive built-in features//
&lt;/h3&gt;

&lt;p&gt;Django comes with an "all-inclusive" approach, providing numerous built-in features like an admin interface, authentication, and template engine, which accelerate development.&lt;br&gt;
high-level abstractions: Django's ORM is tightly integrated and offers a high level of abstraction, which simplifies database interactions.&lt;br&gt;
django's admin interface: The built-in admin interface allows developers to manage application data without writing custom code.&lt;/p&gt;

&lt;h2&gt;
  
  
  weaknesses:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  monolithic architecture//
&lt;/h3&gt;

&lt;p&gt;Django's monolithic structure might be overwhelming for small projects or when developers prefer more modular solutions.&lt;/p&gt;

&lt;h3&gt;
  
  
  learning curve//
&lt;/h3&gt;

&lt;p&gt;Django's extensive features can make the learning curve steep for beginners.&lt;/p&gt;

&lt;h1&gt;
  
  
  ruby on rails:
&lt;/h1&gt;

&lt;h2&gt;
  
  
  strengths:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  convention over configuration//
&lt;/h3&gt;

&lt;p&gt;Ruby on Rails follows the "Convention over Configuration" principle, reducing the need for explicit configuration, resulting in a streamlined development process.&lt;br&gt;
scaffolding: Rails provides powerful scaffolding tools that generate code and basic CRUD (Create, Read, Update, Delete) operations, speeding up development.&lt;/p&gt;

&lt;h2&gt;
  
  
  weaknesses:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  performance//
&lt;/h3&gt;

&lt;p&gt;Ruby on Rails can face performance issues, especially when handling complex and resource-intensive applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  limited language support//
&lt;/h3&gt;

&lt;p&gt;While Rails has good support for Ruby, developers may find fewer resources and libraries compared to Python's extensive ecosystem.&lt;/p&gt;

&lt;p&gt;In conclusion, Flask SQLAlchemy is a valuable tool for building Python-based web applications with relational databases. While it has its strengths, developers must consider their project's requirements and their familiarity with Flask and SQLAlchemy when choosing the right framework for their application.&lt;/p&gt;

&lt;p&gt;It's worth noting that the strengths and weaknesses of frameworks like Flask, Django, and Ruby on Rails can vary based on the specific needs of your project and the preferences of your development team. Additionally, these frameworks are constantly evolving, so it's essential to stay up-to-date with the latest features and improvements to make informed decisions.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>data classes in python</title>
      <dc:creator>dan crowley</dc:creator>
      <pubDate>Fri, 09 Jun 2023 17:00:51 +0000</pubDate>
      <link>https://dev.to/danjpeg/data-classes-in-python-4pd</link>
      <guid>https://dev.to/danjpeg/data-classes-in-python-4pd</guid>
      <description>&lt;p&gt;Python is an object-oriented programming language that provides various ways to define and use classes.&lt;/p&gt;

&lt;h2&gt;
  
  
  python classes
&lt;/h2&gt;

&lt;p&gt;A python class is a blueprint for creating instances / objects.  A normal class is a user-defined class that doesn't include any special attributes or methods.  Normal classes use a constructor method, &lt;code&gt;__init__&lt;/code&gt; that initializes the class instance with default or provided inputs. &lt;/p&gt;

&lt;p&gt;here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Dog:
    def __init__(self, name, breed, age):
        self.name = name
        self.breed = breed
        self.age = age
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  data classes
&lt;/h2&gt;

&lt;p&gt;a data class is a special class created using the @dataclass decorator. they are meant to be used for simple, immutable data structures, sans behavior. &lt;/p&gt;

&lt;p&gt;here's an example of.a nifty little data class in Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from dataclasses import dataclass

@dataclass
class Person:
    name: str
    age: int

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  normal &amp;amp; data classes: differences
&lt;/h1&gt;

&lt;h2&gt;
  
  
  brevity:
&lt;/h2&gt;

&lt;p&gt;Data classes are more concise than normal classes, as they require much less code to define.  The parameters are automatically generated, and a &lt;code&gt;__repr__&lt;/code&gt; is provided for us.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __repr__(self):
        return f"Point(x={self.x}, y={self.y})"

@dataclass
class Point2:
    x: int
    y: int

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

&lt;/div&gt;



&lt;p&gt;Writing attributes is a lot quicker too in a data class. Let's have a look below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def get_name(self):
        return self.name

    def set_name(self, name):
        self.name = name

    def get_age(self):
        return self.age

    def set_age(self, age):
        self.age = age
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we created a normal class named Person and defined two attributes, name and age using a couple pairs of setter and getter functions. &lt;/p&gt;

&lt;p&gt;Now, let's create a data class with two attributes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from dataclasses import dataclass

@dataclass
class Person:
    name: str
    age: int
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Super brief, super legible, super cool!&lt;/p&gt;

&lt;h1&gt;
  
  
  mutability:
&lt;/h1&gt;

&lt;p&gt;Data classes are immutable by default, while normal classes are mutable. &lt;br&gt;
Which means after instances of data classes are made, their attributes can't be edited.&lt;/p&gt;

&lt;p&gt;Is it good to have an object that can't be edited? Like most things in life, it depends. &lt;/p&gt;
&lt;h2&gt;
  
  
  type-hinting:
&lt;/h2&gt;

&lt;p&gt;Type hinting is another area where data classes and normal classes differ. With data classes, we can specify the types of our attributes in the class definition. This is done using Python's built-in type annotations. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from typing import List

@dataclass
class Person:
    name: str
    age: int
    hobbies: List[str]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we specified the types of the name, age, and hobbies attributes. This allows Python's type checker to catch any type errors during development, which can help prevent bugs and improve the reliability of our code.&lt;/p&gt;

&lt;p&gt;In contrast, with normal classes, we have to manually specify the types of our attributes in the constructor or in the class definition. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from typing import List

class Person:
    def __init__(self, name: str, age: int, hobbies: List[str]):
        self.name = name
        self.age = age
        self.hobbies = hobbies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  equality:
&lt;/h1&gt;

&lt;p&gt;By default, data classes define equality based on the values of their attributes, meaning that two instances of a data class are considered equal if all their attributes have the same values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from dataclasses import dataclass

@dataclass
class Person:
    name: str
    age: int

p1 = Person("Alice", 30)
p2 = Person("Alice", 30)
print(p1 == p2)  # True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In contrast, normal classes define equality based on object identity, meaning that two instances of a normal class are considered equal only if they are the same object in memory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

p1 = Person("Alice", 30)
p2 = Person("Alice", 30)
print(p1 == p2)  # False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wow!&lt;/p&gt;

&lt;h1&gt;
  
  
  conclusion
&lt;/h1&gt;

&lt;p&gt;we use both data and normal classes in python to represnt objects. While data classes are more concise and legible, normal classes give us much more versatility.  &lt;/p&gt;

&lt;h1&gt;
  
  
  TLDR: @dataclass(es) are great for simple data structures and "Normal" classes are good when you need more flexibility and function inside your class. thank you please #like #subscribe #comment #follow #your #heart
&lt;/h1&gt;

</description>
    </item>
    <item>
      <title>Using the State Hook to Search and Filter Data</title>
      <dc:creator>dan crowley</dc:creator>
      <pubDate>Wed, 17 May 2023 14:59:38 +0000</pubDate>
      <link>https://dev.to/danjpeg/using-the-state-hook-to-search-and-filter-data-8ce</link>
      <guid>https://dev.to/danjpeg/using-the-state-hook-to-search-and-filter-data-8ce</guid>
      <description>&lt;p&gt;What is a Hook? A Hook is a special function that lets you “hook into” React features.  useState is a special hook that allows us to add React State to function components. &lt;/p&gt;

&lt;p&gt;Before React.js, in order to add state, one had to convert a function to class, but that's no longer necessary with the &lt;code&gt;useState&lt;/code&gt; hook.&lt;/p&gt;

&lt;p&gt;Let's begin by importing the hook to our React app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import { useState } from "react";
import React from "react";

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

&lt;/div&gt;



&lt;p&gt;Once we've imported the hook, we need to create our state variable and setter function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const [searchText, setSearchText] = useState('')

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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;searchText&lt;/code&gt; is our state variable.  It will hold the value of whatever the user types into the input box. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;setSearchText&lt;/code&gt; is our setter function.  By invoking it, we can change or update the state variable.&lt;/p&gt;

&lt;p&gt;Finally, the value in the parenthesis attached to &lt;code&gt;useState&lt;/code&gt; is our default state.  We would like the box to be empty, so we will simply pass an empty string as the parameter.&lt;/p&gt;

&lt;p&gt;If, for any reason, you wanted the search box to already have text inside of it when the user loads the page, you can place something between these parenthesis. &lt;/p&gt;

&lt;h2&gt;
  
  
  setting state with &lt;code&gt;onChange&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Now that we have our setter function, we can use it to build out the function that will handle any change in the search input box.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 const handleSearchInput = (event) =&amp;gt; {
   setSearchText(even.target.value)


      &amp;lt;input type="text"  onChange={handleSearchInput} value={searchText} /&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;So we've created a function &lt;code&gt;handleSearchInput&lt;/code&gt;, and added it to a react event listener, &lt;code&gt;onChange&lt;/code&gt;, so that it will be invoked with every change to the input box. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;handleSearchInput&lt;/code&gt; simply uses our setter function, &lt;code&gt;setSearchText&lt;/code&gt;, passing the &lt;code&gt;event.target.value&lt;/code&gt; (the value of the text inside the search box) as a parameter.  This will update our &lt;code&gt;searchText&lt;/code&gt; state.&lt;/p&gt;

&lt;p&gt;Finally, we also place our &lt;em&gt;deconstructed&lt;/em&gt; searchText variable as the "value" attribute  of the &lt;code&gt;&amp;lt;input /&amp;gt;&lt;/code&gt; tag, ensuring that our value in the &lt;code&gt;searchText&lt;/code&gt; variable and the value in the html remain constant.&lt;/p&gt;

&lt;h2&gt;
  
  
  filtering the data using state
&lt;/h2&gt;

&lt;p&gt;Now that we have our state synced, we need to do &lt;em&gt;something&lt;/em&gt; with this data.  Let's filter it, so that we will only show items with a title that matches the search query.  We can use the built in js &lt;em&gt;filter&lt;/em&gt; method. This method takes a callback function and returns an array that matches the search criterion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const filteredData = data.filter((d) =&amp;gt; {
      return d.title.toLowerCase().includes(searchText.toLowerCase()) 


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

&lt;/div&gt;



&lt;p&gt;Here we name a new constant, that will return an array of data items with a title that matches the search query.  As our setter function is being invoked with each keypress, the user does not need to press enter.  This is a responsive search.&lt;/p&gt;

&lt;p&gt;Yet, &lt;strong&gt;what if there's nothing in the search box?&lt;/strong&gt;  If we want to display all of the available data, we can add an &lt;em&gt;if statement&lt;/em&gt; to our function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const filteredData = data.filter((item) =&amp;gt; {
    if (searchText === "") {
      return true;
    }
    return item.title.toLowerCase().includes(searchText.toLowerCase()) 

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  filtering for multiple cases
&lt;/h2&gt;

&lt;p&gt;Finally, what if we want to return items that match the title or another piece of data, such as an item's description?&lt;/p&gt;

&lt;p&gt;To handle this case, we can add a simple &lt;em&gt;OR statement&lt;/em&gt; &lt;br&gt;
( &lt;code&gt;||&lt;/code&gt; )&lt;br&gt;
to check for a match in either the item's title or description.&lt;br&gt;
&lt;/p&gt;

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


const filteredData = data.filter((item) =&amp;gt; {
    if (searchText === "") {
      return true;
    }
    return item.title.toLowerCase().includes(searchText.toLowerCase()) 

||

items.description.toLowerCase().includes(searchText.toLowerCase())

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

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Javascript Anonymous Functions and Event Listeners</title>
      <dc:creator>dan crowley</dc:creator>
      <pubDate>Wed, 26 Apr 2023 13:10:45 +0000</pubDate>
      <link>https://dev.to/danjpeg/javascript-anonymous-functions-and-event-listeners-2gih</link>
      <guid>https://dev.to/danjpeg/javascript-anonymous-functions-and-event-listeners-2gih</guid>
      <description>&lt;p&gt;&lt;em&gt;Event listeners&lt;/em&gt; and &lt;em&gt;anonymous functions&lt;/em&gt; are a few difficult concepts for beginner developers to properly grasp.  I am constantly receiving questions regarding these concepts from frazzled and frustrated students.  If this sounds like you, fear not, for in this post we will define these concepts, explore their interactions with each other, and discuss potential use cases of each. &lt;/p&gt;

&lt;h2&gt;
  
  
  Event Listeners: addEventListener() method
&lt;/h2&gt;

&lt;p&gt;What is an event listener? An event listener is a method that we pass upon an object, most often Element, Document, or Window.  The method works by adding a function that will be called whenever the specified event is 'heard'.  Let's look at a simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let timesClicked = 0;
const newImg = document.createElement('img');
 newImg.addEventListener('click', timesClicked++);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above creates an image element, and attaches an event listener that is listening for a click event.  When the image element is clicked, the second parameter, &lt;strong&gt;timesClicked++&lt;/strong&gt;, is executed.  This will simply increment the variable &lt;strong&gt;timesClicked&lt;/strong&gt; by one with each click.&lt;/p&gt;

&lt;p&gt;We often provide a callback function as the second parameter of the event listener. Let's see what that might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function incrementVariable() {
 timesClicked++ };

newImg.addEventListener('click', incrementVariable)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will do the exact same thing as the previous example, but instead of providing instructions in the second parameter, we insert just the function name, without any parenthesis.  If we add parenthesis at the end of our function, the function will be called when the code is ran.  We don't want that, we want the function to execute only on the click event. &lt;/p&gt;

&lt;h2&gt;
  
  
  Anonymous Functions and Event Listeners
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;So when do we add parenthesis to our eventListener callback function?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The answer is simple:&lt;/strong&gt; when we need to pass data from a parent function.  Let's look at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addToNav(array) {
    const navList = document.getElementById('cake-list')
    const navName = document.createElement('li')
    navName.textContent = array.name
    navList.appendChild(navName)
    navName.addEventListener('click', () =&amp;gt; {
        displayDetails(array)}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this function, we have one parameter, which is array. This function takes an array, creates a list element with the name, and appends the list element of the item as a child to the navList. Finally, it adds an event listener, which will listen for a click on the newly created list element.  When clicked, it will execute the function &lt;strong&gt;displayDetails&lt;/strong&gt; and pass the array as a parameter.  &lt;/p&gt;

&lt;p&gt;Here, we use an &lt;em&gt;anonymous function&lt;/em&gt; as the second argument of the event listener because we need to pass the array to the callback function in order for the function to properly execute.  &lt;strong&gt;If we simply point to the function, it will not work.&lt;/strong&gt;  As we need to pass information into displayDetails, we must employ an anonymous function, and pass the 'array' variable as the parameter. &lt;strong&gt;This way, our &lt;em&gt;displayDetails&lt;/em&gt; function will know which information to display when the list element is clicked.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Event listeners and anonymous functions can be a bit confusing, but don't get discouraged!  With some practice, one will find they are &lt;strong&gt;much less&lt;/strong&gt; complex than they appear! &lt;/p&gt;

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