<?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: Joe Eames</title>
    <description>The latest articles on DEV Community by Joe Eames (@josepheames).</description>
    <link>https://dev.to/josepheames</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%2F342437%2Fafcfe8ca-6ec2-42c1-9d38-e0595d2250fb.jpg</url>
      <title>DEV Community: Joe Eames</title>
      <link>https://dev.to/josepheames</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/josepheames"/>
    <language>en</language>
    <item>
      <title>Const Is A Lie In JavaScript &amp; Mastering Unit Testing</title>
      <dc:creator>Joe Eames</dc:creator>
      <pubDate>Thu, 03 Dec 2020 17:29:36 +0000</pubDate>
      <link>https://dev.to/thinkster/const-is-a-lie-in-javascript-mastering-unit-testing-1oie</link>
      <guid>https://dev.to/thinkster/const-is-a-lie-in-javascript-mastering-unit-testing-1oie</guid>
      <description>&lt;p&gt;Lately, I've been posting a bunch of really fun content in a series called Mastering Unit Testing on Twitter. The latest tweet is here on the difference between DAMP and DRY in unit testing.&lt;/p&gt;

&lt;p&gt;Please go give it a look and like/retweet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Const is a Lie in JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The const keyword in JavaScript is a lie and a waste. I recently tweeted about how const is a waste and had a lot of interesting discussions.&lt;/p&gt;

&lt;p&gt;But here's the thing about const in JavaScript: it ONLY makes sure that the reference isn't reassigned. But when you use a keyword like const, it implies to you that the thing you're creating is constant, and will remain unchanged throughout the life of the reference. But that's not true. That's not what const does. Even with the best IDE's of today, nothing about this changes.&lt;/p&gt;

&lt;p&gt;So this is totally valid:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5KU9PI7V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2AZrWkFBfbBcUtcF4x%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5KU9PI7V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2AZrWkFBfbBcUtcF4x%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In JavaScript, we use variables that point at primitives sometimes, but we very frequently point at objects/classes that hold multiple pieces of related data. Even if we use const, this data can be changed at will as above.&lt;/p&gt;

&lt;p&gt;Ultimately, const is a little better than a comment when you declare a variable.&lt;/p&gt;

&lt;p&gt;So there are two ways to improve this. First, follow the long time tradition of making constants all uppercase.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--52qfAHrM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2AKBr2Ew50BK8hgneQ%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--52qfAHrM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2AKBr2Ew50BK8hgneQ%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second and even cooler way is to use the Readonly type in TypeScript. Thanks to Val Neekman for this sample:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WgFbphxF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2AlNkN9wdfKvywRmZr%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WgFbphxF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2AlNkN9wdfKvywRmZr%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now, you get REAL constants, not half ones…&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

&lt;p&gt;Signup for my newsletter &lt;a href="https://thinkster.io/?previewmodal=signup?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=constisalie&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Visit Us: &lt;a href="https://thinkster.io?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=constisalie&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;thinkster.io&lt;/a&gt; | Facebook: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
 | Twitter: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>tech</category>
    </item>
    <item>
      <title>Don't Use The Date Object</title>
      <dc:creator>Joe Eames</dc:creator>
      <pubDate>Mon, 16 Nov 2020 16:04:33 +0000</pubDate>
      <link>https://dev.to/thinkster/don-t-use-the-date-object-216n</link>
      <guid>https://dev.to/thinkster/don-t-use-the-date-object-216n</guid>
      <description>&lt;p&gt;JavaScript has a nice Date Object. It can do all kinds of cool things like tell you the current date and time, etc. Lots of languages have a similar facility.&lt;/p&gt;

&lt;p&gt;And you shouldn't use it.&lt;/p&gt;

&lt;p&gt;By that I mean, you shouldn't use it directly.&lt;/p&gt;

&lt;p&gt;Let me clarify a little bit. I don't mean don't use date objects, those are a fundamental data type in JavaScript (or your preferred language). But what I mean is that you shouldn't directly use the functionality that tells you the current date and time, or some calculation based on current date/time, such as getting tomorrow's date. Why?&lt;/p&gt;

&lt;p&gt;Because the date and time is an interaction with an exterior system. Because of how languages incorporate them into basic functionality, we have a hard time seeing that, but you should view it the same way you view the HTTP call that charges a credit card. Would you access the XMLHTTPRequest object directly from your code and hardcode in the URL to charge a credit card? No. You abstract that into its own functionality.&lt;/p&gt;

&lt;p&gt;There are two reasons we do this. The first is that the code is complex and we want to extract it to a simpler interface. That really doesn't apply with getting a date &amp;amp; time. But the second reason does apply. And that reason is that extracting the functionality to somewhere else allows us to test and build our system rapidly by creating fake situations.&lt;/p&gt;

&lt;p&gt;Let's examine a simple application that sends you an email on Wednesday evening at 8 pm to remind you to take the garbage out. How can you test this functionality to assert that it's working? Wait a whole week until Wednesday evening at 8 pm? Definitely not. Would you modify the system date/time on your development machine? Please for the love of all that is good and holy and bug-free don't do that. Maybe you can make the trigger date/time configurable, and when testing, keep setting it to 1 minute from now. Even that isn't the best idea. To test you'll have to keep changing settings in your development data store.&lt;/p&gt;

&lt;p&gt;Instead, imagine you coded your system something like this (I'll use a bit of pseudocode):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AR5cLYRqwu4Q-q6wu%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AR5cLYRqwu4Q-q6wu%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ignore my abstracted pseudocode to make this more readable (JavaScript dates are terribly unreadable). The key here is the "myDateClass" object. I wouldn't actually name it that but you get the point. This isn't the Date() function. This is something else. This class wraps the Date() object/function. The same way that you'd wrap the native XHR object, or any other functionality that accesses an external system. That way you can easily test your system by providing an alternative implementation that makes "now" exactly what you want it to be.&lt;/p&gt;

&lt;p&gt;There are other ways to make this work. You can treat the IsTimeToSendEmail as the abstraction that you fake. You don't need to wrap all the functionality of your built-in Date object. But whatever you do, use an abstraction.&lt;/p&gt;

&lt;p&gt;This is the proper way to use the current Date/Time functionality in a system.&lt;/p&gt;

&lt;p&gt;Most developers don't automatically see the current date/time as an external system, but it is. So abstract accessing it away in its own function/class/service/whatever makes your code easier to write, read, and maintain.&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

&lt;p&gt;Signup for my newsletter &lt;a href="https://thinkster.io/?previewmodal=signup?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=dontusethedateobject&amp;amp;utm_content=&amp;amp;utm_campaign=blog" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Visit Us: &lt;a href="https://thinkster.io?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=dontusethedateobject&amp;amp;utm_content=&amp;amp;utm_campaign=blog" rel="noopener noreferrer"&gt;thinkster.io&lt;/a&gt; | Facebook: &lt;a class="mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt; | Twitter: &lt;a class="mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>tech</category>
    </item>
    <item>
      <title>What's new in Angular 10</title>
      <dc:creator>Joe Eames</dc:creator>
      <pubDate>Thu, 12 Nov 2020 17:47:29 +0000</pubDate>
      <link>https://dev.to/thinkster/what-s-new-in-angular-10-2770</link>
      <guid>https://dev.to/thinkster/what-s-new-in-angular-10-2770</guid>
      <description>&lt;p&gt;Angular 10 is out. Knowing all the newest features of a tool can be very important. So let's break down what's new in Angular 10:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A big fat nothing&lt;/li&gt;
&lt;li&gt;See #1&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Yeah, honestly, there's really nothing new. Ok, there are a couple of tiny changes: Angular Material has a new date picker, and there's some minor changes to things you almost for sure don't use.&lt;/p&gt;

&lt;p&gt;So does this mean that it's a problem? Disappointing?&lt;/p&gt;

&lt;p&gt;Nope. Why? Because first of all, upgrading to 10 will be super easy.&lt;/p&gt;

&lt;p&gt;Also, this matches their release cadence. A new major version every 6 months, regardless of how many features make it in. It's different than other projects run, but it's predictable.&lt;/p&gt;

&lt;p&gt;It also really matters as people look at Angular as a true enterprise framework. Enterprises need stability. Small, incremental, easy-to-update changes are good for an enterprise. The last 2 versions of Angular have been pretty darn simple on the updates. That helps you keep your project from getting stuck on a specific version because upgrading is just too much work.&lt;/p&gt;

&lt;p&gt;So here's a tip: how to update Angular to the latest version with great ease and simplicity:&lt;/p&gt;

&lt;p&gt;ng update @angular/cli @angular/core&lt;/p&gt;

&lt;p&gt;You can see the docs for that command &lt;a href="https://yj685.infusion-links.com/api/v1/click/5324620953288704/5570275139911680"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And generally, that's it. Updating support is a pretty nice feature of Angular.&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

&lt;p&gt;Signup for my newsletter &lt;a href="https://thinkster.io/?previewmodal=signup?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=whatsnewinangular10&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;here&lt;/a&gt;.&lt;br&gt;
Visit Us: &lt;a href="https://thinkster.io?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=whatsnewinangular10&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;thinkster.io&lt;/a&gt; | Facebook: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
 | Twitter: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
&lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>tech</category>
    </item>
    <item>
      <title>Has The Modern Web Made Things Better?</title>
      <dc:creator>Joe Eames</dc:creator>
      <pubDate>Mon, 09 Nov 2020 16:58:43 +0000</pubDate>
      <link>https://dev.to/thinkster/has-the-modern-web-made-things-better-38o5</link>
      <guid>https://dev.to/thinkster/has-the-modern-web-made-things-better-38o5</guid>
      <description>&lt;p&gt;There's been some fascinating discussion and debate recently about the modern web, and whether what we often take for granted as "the right way to do things" is really better than "the old way". A lot of this has been centered around Hey.com, the new email service that's taking the world by storm.&lt;/p&gt;

&lt;p&gt;Now if you're wondering what is the "modern web" let's use a pretty general definition. The modern web is a web app using some kind of front end framework - angular, react, vue, etc. with some kind of API server - node, .NET, Java, or even serverless cloud, and a back end that is possibly relational, but very likely NOSQL, and all the various bits that go with all of that.&lt;/p&gt;

&lt;p&gt;The recent version of this debate started when &lt;a href="https://yj685.infusion-links.com/api/v1/click/5977866340401152/5570275139911680"&gt;Tom Macwright&lt;/a&gt; posted a very interesting blog titled &lt;a href="https://yj685.infusion-links.com/api/v1/click/4664810024992768/5570275139911680"&gt;Second Guessing the Modern Web&lt;/a&gt;. Well worth a read. In response, &lt;a href="https://yj685.infusion-links.com/api/v1/click/4536367673245696/5570275139911680"&gt;Rich Harris&lt;/a&gt;, of whom I'm a great admirer, posted his &lt;a href="https://yj685.infusion-links.com/api/v1/click/6641173841838080/5570275139911680"&gt;In Defense of the Modern Web&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The main points by Tom Macwright were basically "JavaScript is not faster than No JavaScript" which on the face is quite true. Adding overhead to do more still adds overhead. But in the defense post, Rich Harris points out that logic can give you things like caching, lazy loading, and make decisions that actually do improve performance while also improving functionality. Ultimately both are right. JAMstack is a great method that maximizes performance, and a key piece (although not necessarily required) of it is pre-rendering.&lt;/p&gt;

&lt;p&gt;This is all interesting, and I highly recommend you read both blogs, but things REALLY got fascinating when Hey.com posted their tech stack.&lt;/p&gt;

&lt;p&gt;For some background, Hey.com is a new email client that bucks the trends of most email clients with its feature set, and promise of no ads. It's a paid service at $99/year. It's built by the same people who created Ruby on Rails, and who run BaseCamp. It has been wildly popular, but their tech stack reads like something built 12 years ago. They use Rails, the only client-side rendering is Stimulus, a very lightweight JS framework, and some "magic" they discuss, and MySQL. Eschewing the typical "we must use NoSQL" thing.&lt;/p&gt;

&lt;p&gt;The people involved have long been proponents of optimizing for developer happiness and productivity. They use Ruby on Rails for everything, which is very interesting because although Rails is a server-side rendered framework, and the "modern web" looks on server-side rendering the way Obi Wan Kenobi views &lt;a href="https://yj685.infusion-links.com/api/v1/click/5903594154622976/5570275139911680"&gt;blasters&lt;/a&gt;. Yet, Ruby on Rails has long been viewed as one of if not the one technology most loved by its practitioners over basically anything else our industry has produced, although many Smalltalk and Clojure practitioners would beg to argue that point. Nonetheless, there is a very prevalent feeling among those who have used Rails, that nothing they did before or since was as productive and enjoyable. Your own mileage may vary.&lt;/p&gt;

&lt;p&gt;For this and many other reasons, the team behind Hey.com chose to use Rails with minimal client-side rendering. &lt;a href="https://yj685.infusion-links.com/api/v1/click/4852068720050176/5570275139911680"&gt;This twitter thread&lt;/a&gt; documents the stack and many of the surprised and frankly judgemental responses to using this stack.&lt;/p&gt;

&lt;p&gt;For your convenience, here's the breakdown of their stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vanilla Ruby on Rails&lt;/li&gt;
&lt;li&gt;Stimulus (minimal front end "framework" for rails) and a few other tools for front end interactivity&lt;/li&gt;
&lt;li&gt;MySQL&lt;/li&gt;
&lt;li&gt;Redis &amp;amp; ElasticSearch&lt;/li&gt;
&lt;li&gt;AWS/K8S&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Again it's fascinating to note that this tech stack is very much NOT the "modern web". No heavy front end framework. Almost exclusively server-rendered. Relational DB. And they're doing well. By all reports, they're doing really well.&lt;/p&gt;

&lt;p&gt;So does this mean that the "modern web" is really just a bunch of empty promises and unnecessary cruft that we can abandon?&lt;/p&gt;

&lt;p&gt;Perhaps the most interesting response to that original thread is &lt;a href="https://yj685.infusion-links.com/api/v1/click/5694770751733760/5570275139911680"&gt;this response here&lt;/a&gt;, where Rich Harris basically says that although the app is great, there are a few things he would expect of a modern app that don't exist in Hey.com because of the lack of client-side rendering.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Take Away&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This discussion leads us to some interesting takeaways. First, you don't have to use the "latest and greatest". First, mastering a tool will often be more effective than constantly switching to whatever came out in the last five minutes. Second, new tools and techniques can give you capabilities that don't exist in older ones. But perhaps my favorite takeaway was that we are looking at what a top-notch team can produce give tools they have been mastering for years. This probably indicates that this isn't a good reference point for all of us "average humans". When you see a true master using a tool and think that the difference is the tool, and not the hands using it, you may be missing the forest for the trees. I'll illustrate this with an apocryphal golf story.&lt;/p&gt;

&lt;p&gt;A man was golfing with Tiger Woods. Tiger hit a particularly good shot, and the man asked him which club he used. Tiger didn't reply. Instead, he went to his bag, pulled out two more golf clubs, and went back to where he hit the shot. He dropped two more balls and proceeded to make essentially the exact same shot with the exact same fantastic result with the other two clubs. When he was done, he asked the man if he still wanted to know which club he used.&lt;/p&gt;

&lt;p&gt;It's good to learn new tools, but to be a great programmer, don't focus on the tools.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;Signup for my newsletter &lt;a href="https://thinkster.io/?previewmodal=signup?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=themodernweb&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Visit Us: &lt;a href="https://thinkster.io?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=themodernweb&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;thinkster.io&lt;/a&gt; | Facebook: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
 | Twitter: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>tech</category>
    </item>
    <item>
      <title>Beware of Vanilla JS</title>
      <dc:creator>Joe Eames</dc:creator>
      <pubDate>Thu, 05 Nov 2020 15:23:02 +0000</pubDate>
      <link>https://dev.to/thinkster/beware-of-vanilla-js-kkl</link>
      <guid>https://dev.to/thinkster/beware-of-vanilla-js-kkl</guid>
      <description>&lt;p&gt;I like to paint miniature figures for &lt;a href="https://yj685.infusion-links.com/api/v1/click/4743827101057024/5570275139911680" rel="noopener noreferrer"&gt;Star Wars&lt;/a&gt; (pics below for anyone who may be interested). It's about the geekiest of hobbies. The other day I was on a website buying custom bases for these figures. This site was out of the US, and the default currency was not US Dollars, but there was an option to switch the currency to US dollars so I did, and then I noticed this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AWgyR6_DDS5bl3Wp8%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AWgyR6_DDS5bl3Wp8%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Look closely. What's going on here? That's not US dollars. US dollars show the currency before the number, and it uses a point not a comma to separate the integer from the decimal portion of a number. And how did this happen? Long story short, the developers decided to use a minimal amount of JavaScript and manage currency conversion and formatting themselves. And unfortunately, localization, like so many issues, has a lot of nuances that aren't obvious if you just learn a little. You have to dig deep and almost become an expert. A lot of currencies use commas and many use points, the placement of the symbol varies. Knowing these issues is just one of many things you have to worry about in building an app.&lt;/p&gt;

&lt;p&gt;This is the value of front end frameworks. When they give you currency formatting tools, then someone has done all the research and you can reasonably trust that they'll get things right. In my free course on the &lt;a href="https://yj685.infusion-links.com/api/v1/click/5068791993860096/5570275139911680" rel="noopener noreferrer"&gt;Fundamentals of Angular&lt;/a&gt; we cover the &lt;a href="https://yj685.infusion-links.com/api/v1/click/4799965024747520/5570275139911680" rel="noopener noreferrer"&gt;currency pipe&lt;/a&gt; for formatting currencies, and it's surprising how many options there are for currencies. But that pipe means you don't have to worry about how to format currencies. Angular does it for you.&lt;/p&gt;

&lt;p&gt;Ultimately this was a fairly minor issue, but nonetheless, it's indicative of something bigger. There's a fair amount of discussion of minimalism as our web apps initial download sizes get bigger and bigger and people push for better lighthouse scores.&lt;/p&gt;

&lt;p&gt;So Do we need to use a framework for everything? No. And you can certainly find some library that handles currency for you. But that's only one issue. Even in a relatively simple issue, you'll have dozens of issues like that. Finding a different library for each issue is basically just piecing together a front end framework by hand.&lt;/p&gt;

&lt;p&gt;This doesn't mean that every web application has to be built with React or another similar framework. But realize what you're giving up if you don't use a framework at all.&lt;/p&gt;

&lt;p&gt;And in today's modern world there's a fair set of next generation minimalist frameworks you can use. Starting with &lt;a href="https://yj685.infusion-links.com/api/v1/click/4564478443913216/5570275139911680" rel="noopener noreferrer"&gt;Preact&lt;/a&gt;, which gives you 90% of React for 10% of the size, there's also Svelte, and recently &lt;a href="https://yj685.infusion-links.com/api/v1/click/4715350343811072/5570275139911680" rel="noopener noreferrer"&gt;AlpineJS&lt;/a&gt; and &lt;a href="https://yj685.infusion-links.com/api/v1/click/5850920101085184/5570275139911680" rel="noopener noreferrer"&gt;CrankJS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You still need to learn JavaScript. It's the underpinnings of everything you will do on the web, which is a good time to point out our new course, &lt;a href="https://yj685.infusion-links.com/api/v1/click/4516028025143296/5570275139911680" rel="noopener noreferrer"&gt;JavaScript Fundamentals&lt;/a&gt;. If you're a pro user you can access that course now.&lt;/p&gt;

&lt;p&gt;But just &lt;a href="https://yj685.infusion-links.com/api/v1/click/4624952606851072/5570275139911680" rel="noopener noreferrer"&gt;vanilla JS&lt;/a&gt; (hehe) by itself is a dangerous road to take.&lt;/p&gt;

&lt;p&gt;As you make these decisions, being educated about the trade-offs can be very important. But the most important thing, as always, is to just build stuff and learn.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;Signup for my newsletter &lt;a href="https://thinkster.io/?previewmodal=signup?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=bewareofvanillajs&amp;amp;utm_content=&amp;amp;utm_campaign=blog" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Visit Us: &lt;a href="https://thinkster.io?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=bewareofvanillajs&amp;amp;utm_content=&amp;amp;utm_campaign=blog" rel="noopener noreferrer"&gt;thinkster.io&lt;/a&gt; | Facebook: &lt;a class="mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt; | Twitter: &lt;a class="mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2A7d8q9fuJr_TisQk9%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2A7d8q9fuJr_TisQk9%3F" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F293%2F0%2AftguBUluKVY5Jp-z%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F293%2F0%2AftguBUluKVY5Jp-z%3F" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2ABIrWdCgorly8rGR5%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2ABIrWdCgorly8rGR5%3F" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2Awgn1ufTEkYpz0n80%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2Awgn1ufTEkYpz0n80%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>angular</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The Tricky Part of Validation Attributes in Angular</title>
      <dc:creator>Joe Eames</dc:creator>
      <pubDate>Fri, 30 Oct 2020 17:40:29 +0000</pubDate>
      <link>https://dev.to/thinkster/the-tricky-part-of-validation-attributes-in-angular-1n</link>
      <guid>https://dev.to/thinkster/the-tricky-part-of-validation-attributes-in-angular-1n</guid>
      <description>&lt;p&gt;In my &lt;a href="https://yj685.infusion-links.com/api/v1/click/5427489536737280/5570275139911680"&gt;free course on the Fundamentals of Angular&lt;/a&gt;, there are just over 2 hours of content on &lt;a href="https://yj685.infusion-links.com/api/v1/click/4815748553506816/5570275139911680"&gt;template-driven forms&lt;/a&gt; in Angular. One of the main parts of this is coverage of how to validate user input. This is an important part of any framework's forms handling.&lt;/p&gt;

&lt;p&gt;But in Angular, there's a bit of an unmet promise when you learn about forms validation, and this can be confusing, so I'd like to just quickly cover the issue to help clear up any confusion you may encounter when doing forms validation in Angular.&lt;/p&gt;

&lt;p&gt;When you first learn about forms validation, you quickly discover that there are several attributes you can add to an input control to validate that control. Angular's integration with this validation is simple and effective. It's a bit like magic.&lt;/p&gt;

&lt;p&gt;Want to make sure that a field is required? Simply add the "required" attribute to the input element. Angular handles the rest for you. Want to make sure that a password has at least 8 characters? Use the minlength attribute. There's maxlength as well. And if you really have a tough validation problem, then there's the pattern attribute which uses regular expressions, and as they say, &lt;a href="https://yj685.infusion-links.com/api/v1/click/4669971424346112/5570275139911680"&gt;"now you have two problems"&lt;/a&gt; lol.&lt;/p&gt;

&lt;p&gt;These attributes are part of the HTML5 spec, so using them is really natural. You're just leveraging the built-in parts of HTML and Angular is just making them five times more awesome.&lt;/p&gt;

&lt;p&gt;So after learning these four attributes you may think "awesome, what other HTML validation attributes are there that I can use? Some quick Googling (or Binging?) will lead you to several more of these same validation attributes. There's min &amp;amp; max for dates &amp;amp; numbers, there's a step somewhat more obtuse attribute, and of course there's the good old type attribute on input elements. Such as type="email" and then suddenly you discover the unmet tacit promise of Angular validation.&lt;/p&gt;

&lt;p&gt;Because these attributes do nothing with Angular validation. Nada. Squat.&lt;/p&gt;

&lt;p&gt;At first, you may think that you're just not doing them right. But that's not it. They're not used by Angular. The framework simply doesn't utilize them. If you want to mimic them, you have to create custom validators yourself.&lt;/p&gt;

&lt;p&gt;Now there is logic behind all this but ultimately it doesn't matter. You just need to know what is and is not supported. So here's a summary of useful information when doing validation in Angular's template-driven forms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Supported Validation Attributes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;required&lt;/li&gt;
&lt;li&gt;pattern&lt;/li&gt;
&lt;li&gt;minlength&lt;/li&gt;
&lt;li&gt;maxlength&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Unsupported Validation Attributes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;type&lt;/li&gt;
&lt;li&gt;min&lt;/li&gt;
&lt;li&gt;max&lt;/li&gt;
&lt;li&gt;step&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So don't get confused if you run into this. It's just the way it is.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;Signup for my newsletter &lt;a href="https://thinkster.io/?previewmodal=signup?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=validationattributes&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Visit Us: &lt;a href="https://thinkster.io?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=validationattributes&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;thinkster.io&lt;/a&gt; | Facebook: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
 | Twitter: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
&lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>tech</category>
    </item>
    <item>
      <title>The Best 3 Angular Conference Talks this Year</title>
      <dc:creator>Joe Eames</dc:creator>
      <pubDate>Thu, 15 Oct 2020 16:02:26 +0000</pubDate>
      <link>https://dev.to/thinkster/the-best-3-angular-conference-talks-this-year-55p4</link>
      <guid>https://dev.to/thinkster/the-best-3-angular-conference-talks-this-year-55p4</guid>
      <description>&lt;p&gt;Earlier this year I was privileged to be able to help put on ng-conf Hardwired, a last-minute, seat of our pants scramble to turn an in-person conference into an online conference that was all duct tape and baling wire behind the scenes, but turned out great for the audience.&lt;/p&gt;

&lt;p&gt;Anyway, I thought I'd just put out there that there were a few talks given at the conference that were truly epic and are absolute must-sees. These are pretty Angular-centric, FYI.&lt;/p&gt;

&lt;p&gt;So here's my list in no particular order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://yj685.infusion-links.com/api/v1/click/6585070011547648/5570275139911680"&gt;Farewell Entry Components&lt;/a&gt; by Yvonne Allen. Yvonne, who happens to be a Thinkster author, gave one of the most unique talks I've ever seen at a conference. It's not your typical lecture, but instead, a fake newscast where she discusses new features in Angular 9. It's as informative as it is entertaining. Go check it out.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://yj685.infusion-links.com/api/v1/click/6401168739401728/5570275139911680"&gt;Resilient Angular Testing&lt;/a&gt; - Jaw-Dropping Magic Tricks by the Magnificent Shai Rezniko. As the name implies, this is another one of those talks that has to be experienced to be understood. It's got great information on Angular unit testing and is again a fully entertaining talk.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://yj685.infusion-links.com/api/v1/click/4772559117352960/5570275139911680"&gt;How Ivy Will Improve Your Application Architecture&lt;/a&gt;. Manfred Steyer is one of the superheroes of Angular. His in-depth technical knowledge is nearly unsurpassed. This talk lays out some of the ways that the new Ivy engine will affect your Angular applications. Be sure to get rid of any distractions, this is a deep and esoteric talk.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So if you get some time, be sure to check out these talks.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;Signup for my newsletter &lt;a href="https://thinkster.io/?previewmodal=signup?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=best3angulartalks&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Visit Us: &lt;a href="https://thinkster.io?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=best3angulartalks&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;thinkster.io&lt;/a&gt; | Facebook: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
 | Twitter: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
&lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>tech</category>
    </item>
    <item>
      <title>The Most Misleading Part of Angular Forms Validation</title>
      <dc:creator>Joe Eames</dc:creator>
      <pubDate>Thu, 08 Oct 2020 17:14:10 +0000</pubDate>
      <link>https://dev.to/thinkster/the-most-misleading-part-of-angular-forms-validation-2ghp</link>
      <guid>https://dev.to/thinkster/the-most-misleading-part-of-angular-forms-validation-2ghp</guid>
      <description>&lt;p&gt;In my &lt;a href="https://yj685.infusion-links.com/api/v1/click/5870754111160320/5570275139911680"&gt;free course on the Fundamentals of Angular&lt;/a&gt;, there are just over 2 hours of content on &lt;a href="https://yj685.infusion-links.com/api/v1/click/5371623177453568/5570275139911680"&gt;template-driven forms&lt;/a&gt; in Angular. One of the main parts of this is coverage of how to validate user input. This is an important part of any framework's forms handling.&lt;/p&gt;

&lt;p&gt;But in Angular, there's a bit of an unmet promise when you learn about forms validation, and this can be confusing, so I'd like to just quickly cover the issue to help clear up any confusion you may encounter when doing forms validation in Angular.&lt;/p&gt;

&lt;p&gt;When you first learn about forms validation, you quickly discover that there are several attributes you can add to an input control to validate that control. Angular's integration with this validation is simple and effective. It's a bit like magic.&lt;/p&gt;

&lt;p&gt;Want to make sure that a field is required? Simply add the "required" attribute to the input element. Angular handles the rest for you. Want to make sure that a password has at least 8 characters? Use the minlength attribute. There's maxlength as well. And if you really have a tough validation problem, then there's the pattern attribute which uses regular expressions, and as they say, &lt;a href="https://yj685.infusion-links.com/api/v1/click/5809169682399232/5570275139911680"&gt;"now you have two problems"&lt;/a&gt; lol.&lt;/p&gt;

&lt;p&gt;These attributes are part of the HTML5 spec, so using them is really natural. You're just leveraging the built-in parts of HTML and Angular is just making them five times more awesome.&lt;/p&gt;

&lt;p&gt;So after learning these four attributes you may think "awesome, what other HTML validation attributes are there that I can use? Some quick Googling (or Binging?) will lead you to several more of these same validation attributes. There's min &amp;amp; max for dates &amp;amp; numbers, there's step a somewhat more obtuse attribute and of course, there's the good old type attribute on input elements. Such as type="email" and then suddenly you discover the unmet tacit promise of Angular validation.&lt;/p&gt;

&lt;p&gt;Because these attributes do nothing with Angular validation. Nada. Squat.&lt;/p&gt;

&lt;p&gt;At first, you may think that you're just not doing them right. But that's not it. They're not used by Angular. The framework simply doesn't utilize them. If you want to mimic them, you have to create custom validators yourself.&lt;/p&gt;

&lt;p&gt;Now there is logic behind all this but ultimately it doesn't matter. You just need to know what is and is not supported. So here's a summary of useful information when doing validation in Angular's template-driven forms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Supported Validation Attributes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;required&lt;/li&gt;
&lt;li&gt;pattern&lt;/li&gt;
&lt;li&gt;minlength&lt;/li&gt;
&lt;li&gt;maxlength&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Unsupported Validation Attributes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;type&lt;/li&gt;
&lt;li&gt;min&lt;/li&gt;
&lt;li&gt;max&lt;/li&gt;
&lt;li&gt;step&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So don't get confused if you run into this. It's just the way it is.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;Signup for my newsletter &lt;a href="https://thinkster.io/?previewmodal=signup?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=misleadingpartofangularforms&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;here&lt;/a&gt;.&lt;br&gt;
Visit Us: &lt;a href="https://thinkster.io?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=misleadingpartofangularforms&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;thinkster.io&lt;/a&gt; | Facebook: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
 | Twitter: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
&lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>tech</category>
    </item>
    <item>
      <title>What Should You Put in a Constructor vs ngOnInit in Angular</title>
      <dc:creator>Joe Eames</dc:creator>
      <pubDate>Mon, 05 Oct 2020 15:55:33 +0000</pubDate>
      <link>https://dev.to/thinkster/what-should-you-put-in-a-constructor-vs-ngoninit-in-angular-3apl</link>
      <guid>https://dev.to/thinkster/what-should-you-put-in-a-constructor-vs-ngoninit-in-angular-3apl</guid>
      <description>&lt;p&gt;One of the most confusing things when building an Angular component is deciding what to put in the constructor and what to put in the ngOnInit method. Both of these methods are used for similar purposes, both fire once at the beginning of the life of a component, so knowing what to put where can be troublesome. In this article, we'll break down when to use each method, and why, and what to put in them, and what NOT to put in them.&lt;/p&gt;

&lt;p&gt;First, let's break down what each method does, and when it's fired.&lt;/p&gt;

&lt;p&gt;The constructor is important in a component for two reasons. First, it's a lifecycle method, meaning it is called when the component is constructed, so, therefore, it has an important purpose in that if you want specific code to run at a certain time (during construction) then this is the right place to do it. Second, it's the place where you inject services into the component. It looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AdHtmOA8meyit4OqT%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AdHtmOA8meyit4OqT%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note the use of TypeScript here. First we use the private keyword so that we retain a reference to our actor service. Second, we type the "actorService" variable with the "ActorService" type to let Angular know which service we want.&lt;/p&gt;

&lt;p&gt;The ngOnInit method on the other hand, serves only as a lifecycle method, firing when a component is initialized.&lt;/p&gt;

&lt;p&gt;Both construction and initialization take place at very similar times in the life of a component. And we often want certain kinds of code to run when our component is "created".&lt;/p&gt;

&lt;p&gt;Some typical code to run here would be initializing internal state properties, loading data of which the component is in charge, usually via HTTP calls, calling initial methods on injected services, and starting up processes or calculations.&lt;/p&gt;

&lt;p&gt;So should we do this during construction or initialization?&lt;/p&gt;

&lt;p&gt;Construction happens when the JavaScript class is constructed. It's essentially the first thing that can happen to a class instance. Initialization, on the other hand, happens after that when the component is fully initialized. In essence, this means when Angular is done plugging all the pieces together.&lt;/p&gt;

&lt;p&gt;Using this knowledge we can now look at best practices with these two methods, what to put in each, and what not to put in each.&lt;/p&gt;

&lt;p&gt;Construction is first, but happens when the component isn't really a component yet. So therefore the constructor should only contain very basic simple code relating to basic initialization of the class. You will have the injected services, but that's about it. So typically we only put simple quick code such as state initialization. Although it's usually simpler to initialize those properties where they are declared if possible.&lt;/p&gt;

&lt;p&gt;So do this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ATFSt1X-4NJiwJUgq%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ATFSt1X-4NJiwJUgq%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instead of this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ApTb8LPbFpmItlWp-%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2ApTb8LPbFpmItlWp-%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The only time to use the latter method is if you need access to an injected service when initializing state.&lt;/p&gt;

&lt;p&gt;The ngOnInit method, on the other hand fires when the component is ready to be a component and ready to get to work. Therefore, just about all startup code should be placed here by default. Whether this is making HTTP calls, making calls to dependent services, or other similar items. We can even put our initial state initialization here and it's just fine. There's no drawback to putting it here instead of in the constructor.&lt;/p&gt;

&lt;p&gt;So a quick rule of thumb honestly is to consider code in the constructor to be a code smell, and look at it closely to make sure that it shouldn't actually be in your ngOnInit method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ngOnInit gotcha:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The ngOnInit method does have one gotcha. And that is that even if we change routes, if we're using the same component for both the previous and current route, then the ngOnInit method isn't fired again.&lt;/p&gt;

&lt;p&gt;This commonly happens when looking at the details of an item in a list using a component as the detail view, for example, the details of an actor, and if that view has "next actor" and "previous actor" links. Then clicking those links to view the details of a different actor might change the route, but it doesn't cause the ngOnInit method to fire again. So be careful in this case.&lt;/p&gt;

&lt;p&gt;For more on constructors and the ngOnInit method, check out my &lt;a href="https://yj685.infusion-links.com/api/v1/click/5483787259215872/5570275139911680" rel="noopener noreferrer"&gt;Fundamentals of Angular&lt;/a&gt; course, completely free, on Thinkster.io.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;Signup for my newsletter &lt;a href="https://thinkster.io/?previewmodal=signup?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=putinaconstructor&amp;amp;utm_content=&amp;amp;utm_campaign=blog" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Visit Us: &lt;a href="https://thinkster.io?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=putinaconstructor&amp;amp;utm_content=&amp;amp;utm_campaign=blog" rel="noopener noreferrer"&gt;thinkster.io&lt;/a&gt; | Facebook: &lt;a class="mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt; | Twitter: &lt;a class="mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>tech</category>
    </item>
    <item>
      <title>Arguments vs Parameters and The Rest Parameter</title>
      <dc:creator>Joe Eames</dc:creator>
      <pubDate>Thu, 01 Oct 2020 21:30:13 +0000</pubDate>
      <link>https://dev.to/thinkster/arguments-vs-parameters-and-the-rest-parameter-105n</link>
      <guid>https://dev.to/thinkster/arguments-vs-parameters-and-the-rest-parameter-105n</guid>
      <description>&lt;p&gt;Knowing the difference between arguments and parameters can be important.&lt;/p&gt;

&lt;p&gt;But before we begin, just a quick note that our new course, &lt;a href="https://yj685.infusion-links.com/api/v1/click/5049498403078144/5570275139911680" rel="noopener noreferrer"&gt;Fundamentals of Angular&lt;/a&gt;, is out and completely free. That's right. 100% free. Nothing behind a paywall. This isn't a half course or anything. This is the whole enchilada. Go check it out.&lt;/p&gt;

&lt;p&gt;And for a video version of this blog, click &lt;a href="https://yj685.infusion-links.com/api/v1/click/5194054016696320/5570275139911680" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I recently ran a quick little &lt;a href="https://yj685.infusion-links.com/api/v1/click/5939177189015552/5570275139911680" rel="noopener noreferrer"&gt;twitter poll&lt;/a&gt; to see if people, in general, knew the difference between parameters and arguments. The results of the poll were quite interesting.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AnKeEWvYv-ZzbpMoF%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AnKeEWvYv-ZzbpMoF%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Only 50% of people were confident with the difference between arguments and parameters, which makes this a good subject to review.&lt;/p&gt;

&lt;p&gt;An argument is the value you pass into a function. A parameter is the name the function assigns to that value. That is the difference. Often times we use these two terms interchangeably, and most of the time the difference is unimportant. But it can matter, so learning the difference, and learning to use the appropriate term at the appropriate time can help with communication of all kinds.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AqcyD6WkYrrYRopv3%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AqcyD6WkYrrYRopv3%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, "itemName" and "quantity" are parameters, and "handSanitizer" and 300 are arguments.&lt;/p&gt;

&lt;p&gt;This actually clues us in as to why we the arguments object in JavaScript is named arguments, and not parameters. Arguments are the values, not the names. The arguments object contains the values, but doesn't care about the names.&lt;/p&gt;

&lt;p&gt;If you're not familiar with the arguments object, it's a global object that gives you information about the arguments used in the function call for the current context.&lt;/p&gt;

&lt;p&gt;So in this example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AVH7ktkRkt2cKQyNV%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AVH7ktkRkt2cKQyNV%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how the arguments object was never created or referenced, it just exists. Inside that function, those three calls will log out "2", "Hand Sanitizer" and "300" respectively.&lt;/p&gt;

&lt;p&gt;Now, why is there an arguments object when we have the named parameters anyway?&lt;/p&gt;

&lt;p&gt;Well, JavaScript is just so loosey-goosey that it doesn't care if you pass it more arguments than there are parameters.&lt;/p&gt;

&lt;p&gt;Now, look at the sentence I just typed. This is a GREAT example of why we need to understand the difference between arguments and parameters. If you use those two terms interchangeably, then the sentence makes no sense. But they're not the same thing. And understanding them lets us learn about things like the arguments object.&lt;/p&gt;

&lt;p&gt;So continuing on, you can pass more arguments than there are parameters. Let's look at a case for this. Let's say we want a function that can receive a list of numbers and add them all up, but doesn't require that they're in an array, and can instead be passed in as separate arguments. Doing this with separate arguments would be impossible, and even if we do our best it's messy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AAnug5jhrXcvY9-50%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AAnug5jhrXcvY9-50%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But with the arguments object, this is trivial. Since the arguments object only has the arguments that were already passed in, it's basically an array of numbers we just add up.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AJhpuukVOO-QA2am7%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AJhpuukVOO-QA2am7%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unfortunately, arguments is only an array-like object, and not a full array, so we can't do things like reduce().&lt;/p&gt;

&lt;p&gt;But thank you EcmaScript for coming to the rescue here. The Rest Parameter is a way to get the best of both worlds.&lt;/p&gt;

&lt;p&gt;A rest parameter is a special parameter in a function signature (good thing we know what a parameter is vs. an argument) that is signified by three dots before it. It must be the very last parameter in a function signature. This parameter receives all the arguments that don't have named parameters already, and is an array of those arguments.&lt;/p&gt;

&lt;p&gt;So our new AddEverythingUp method would look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AOmtb5eIXhn-o3hBI%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AOmtb5eIXhn-o3hBI%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can mix in named parameters (only before the rest parameter).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A5QW-5E_dcUDXrq9e%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A5QW-5E_dcUDXrq9e%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So for most uses, a rest parameter is preferred over the arguments object, and many developers now consider the arguments object to be a code smell.&lt;/p&gt;

&lt;p&gt;And that's the rest parameter, and also arguments and parameters. Think you get it? Try &lt;a href="https://yj685.infusion-links.com/api/v1/click/6458921382051840/5570275139911680" rel="noopener noreferrer"&gt;this challenge&lt;/a&gt; and see if you can solve it!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to learn five times faster&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here at Thinkster, we use educational science to teach you five times faster than just about anything else out there. How? With proper instruction based on educational principles and hands-on exercises, you will retain 75% to 90% of what you learn. Without these techniques, you only remember 7% to 15% of what you learn. That's why you can watch a video or a course or read a blog and feel like you need to watch a couple more before you really "get it".&lt;/p&gt;

&lt;p&gt;You can see this in action in our courses. And you can get it for free in our Fundamentals of Angular course. Go check it out.&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

&lt;p&gt;Signup for my newsletter &lt;a href="https://thinkster.io/?previewmodal=signup?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=argumentvsparameter&amp;amp;utm_content=&amp;amp;utm_campaign=blog" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Visit Us: &lt;a href="https://thinkster.io?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=argumentvsparameter&amp;amp;utm_content=&amp;amp;utm_campaign=blog" rel="noopener noreferrer"&gt;thinkster.io&lt;/a&gt; | Facebook: &lt;a class="mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt; | Twitter: &lt;a class="mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>tech</category>
    </item>
    <item>
      <title>Angular Lazy Loading Syntax Under the Hood</title>
      <dc:creator>Joe Eames</dc:creator>
      <pubDate>Tue, 29 Sep 2020 01:47:18 +0000</pubDate>
      <link>https://dev.to/thinkster/angular-lazy-loading-syntax-under-the-hood-ej3</link>
      <guid>https://dev.to/thinkster/angular-lazy-loading-syntax-under-the-hood-ej3</guid>
      <description>&lt;p&gt;Before we get started, I want to make sure that you were aware of the fact that our new &lt;a href="https://yj685.infusion-links.com/api/v1/click/5468075379654656/5570275139911680"&gt;Fundamentals of Angular&lt;/a&gt; course (my new course) is out and it is completely free! Seriously. The whole thing. All 41 hands-on exercises, all 13 hours, all free. Go through the whole course and never pay a dime (or ruble or shekel or whatever). Plus we got even crazier and we've &lt;a href="https://yj685.infusion-links.com/api/v1/click/5380933387288576/5570275139911680"&gt;made a way&lt;/a&gt; that you can actually get paid to go through the course.&lt;/p&gt;

&lt;p&gt;Ok, on to the knowledge!&lt;/p&gt;

&lt;p&gt;If you want a video version of this newsletter, you can find it &lt;a href="https://yj685.infusion-links.com/api/v1/click/4810219902992384/5570275139911680"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With complex front end applications, the size of an application often exceeds what is reasonable and creates a huge initial download. So one of the primary strategies for improving the performance of these types of applications is to cut down the initial download size, and deliver the rest of the application as needed, generally in a lazy-loaded manner.&lt;/p&gt;

&lt;p&gt;In my new &lt;a href="https://yj685.infusion-links.com/api/v1/click/5497923196157952/5570275139911680"&gt;Fundamentals of Angular&lt;/a&gt; course, we cover lazy loading pieces of your Angular application. In this section, we learn how to create a lazy-loaded module and associated route using the loadChildren method in the route configuration. This is an example of how it looks:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EQfEpa2o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2A014aIQpP5OP_nwIy%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EQfEpa2o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2A014aIQpP5OP_nwIy%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This syntax is a bit different and may seem confusing at first glance, but if we take a minute and break it down there's a lot to learn from just this one piece of code.&lt;/p&gt;

&lt;p&gt;First, the loadChildren property takes a callback function. This function receives no parameters. Inside this callback function, we call the import function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c-UeImPw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2Aja0j_XRebyqrCv4s%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c-UeImPw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2Aja0j_XRebyqrCv4s%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This function isn't an Angular function, this is a basic part of JavaScript and the Browser. This allows the browser to dynamically download a file the moment this code is executed. If you're interested, I previously blogged about the difference between the static import statement and the dynamic import function. You can find that blog &lt;a href="https://yj685.infusion-links.com/api/v1/click/5887039448547328/5570275139911680"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Using the import function like this means that the moment the user attempts to navigate to this route (or any route containing this as the base part of the path), the referenced module is then downloaded.&lt;/p&gt;

&lt;p&gt;In actuality, what the Angular build process creates is a bundle, and that bundle is what gets downloaded, but the bundle is an Angular module, so we can use the two terms interchangeably. This bundle is a single file, so when we call the import function, it downloads a single file which is the entire bundle and the entire module. The Angular build engine also includes anything the module directly references that wouldn't have been downloaded in the initial main download for the application.&lt;/p&gt;

&lt;p&gt;Now the import function returns a promise. That promise resolves when the requested file is downloaded, so that way we can take an action when code gets downloaded. That of course is done in the .then() function. This function looks like this in our example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v_Hj2TbJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2Azf8bxMgbb8c1phdo%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v_Hj2TbJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2Azf8bxMgbb8c1phdo%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is an extremely important part of the whole process. Once the module (not just the module class, but everything that is part of the module) is downloaded, this function receives the downloaded code and returns the module class for Angular to process.&lt;/p&gt;

&lt;p&gt;The fact that it's being returned is critical to understand. We can see that is what's happening by noticing that there are no curly braces.&lt;/p&gt;

&lt;p&gt;That code is actually equivalent to this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P1oDaqLQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2AIBZmSglb1_ES9m_X%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P1oDaqLQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2AIBZmSglb1_ES9m_X%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Without the curly braces in an arrow function like this, there is an implicit return statement. But if the code looked like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0AOnldrx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2As4HEsj1DNUw-HR_X%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0AOnldrx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2As4HEsj1DNUw-HR_X%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;then there would be nothing getting returned from the promise.&lt;/p&gt;

&lt;p&gt;When the module gets returned from that promise, the Angular framework receives that module, and then loads and processes it and all of its parts. Our lazy-loaded code is now part of the project as if it had been there from the start!&lt;/p&gt;

&lt;p&gt;So here's a quick review/overview of the entire process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We use the loadChildren key which triggers a function when that route is requested&lt;/li&gt;
&lt;li&gt;The JavaScript import function downloads the indicated module bundle&lt;/li&gt;
&lt;li&gt;After the download completes, the promise resolves, and we return the module class in the .then() function so that Angular can now begin loading and processing the module.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Breaking down a complex construct like this is useful for learning not only the framework we are using, but also JavaScript. I hope you got something out of this!&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;Signup for my newsletter &lt;a href="https://thinkster.io/?previewmodal=signup?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=angularlazyloading&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Visit Us: &lt;a href="https://thinkster.io?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=angularlazyloading&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;thinkster.io&lt;/a&gt; | Facebook: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
 | Twitter: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>produtivity</category>
      <category>tech</category>
    </item>
    <item>
      <title>The Difference Between the Import function and the Import Statement</title>
      <dc:creator>Joe Eames</dc:creator>
      <pubDate>Thu, 24 Sep 2020 16:00:35 +0000</pubDate>
      <link>https://dev.to/thinkster/the-difference-between-the-import-function-and-the-import-statement-17me</link>
      <guid>https://dev.to/thinkster/the-difference-between-the-import-function-and-the-import-statement-17me</guid>
      <description>&lt;p&gt;In my new &lt;a href="https://yj685.infusion-links.com/api/v1/click/6184021656338432/5570275139911680"&gt;Fundamentals of Angular&lt;/a&gt; course that is being released later this week, I cover lazy loading with Angular feature modules. In the section on lazy loading, we encounter the import() function. One of the things that can be confusing about this function is how it compares to the more common import statement.&lt;/p&gt;

&lt;p&gt;I've previously written about the import statement and how it can be confusing. If you want a deeper dive on that, check out my blog &lt;a href="https://yj685.infusion-links.com/api/v1/click/5492875435180032/5570275139911680"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's take a quick look at the import statement and the import function in JavaScript.&lt;/p&gt;

&lt;p&gt;The import statement is what allows us to divide up our JavaScript into multiple files without using Script tags and ugly globals.&lt;/p&gt;

&lt;p&gt;Generally, the import statement looks something like this and appears at the top of our files:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iA2N8lK6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2AYO27KmlHbu2V5YZv%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iA2N8lK6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2AYO27KmlHbu2V5YZv%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This statement is a static import. Whatever engine is processing our JavaScript to bundle up for delivery to the browser will crawl all the import statements we have in our files, and create one large bundle. In general, this is desirable. It allows for static analysis of our files, and advanced optimizations like tree shaking and dead code removal.&lt;/p&gt;

&lt;p&gt;But it doesn't allow us to either delay the inclusion of some code into our client-side project, or delay the download and loading of some of our code.&lt;/p&gt;

&lt;p&gt;As projects get bigger and more complex and we use larger and larger frameworks and more and more third-party tools, our initial bundle can get unreasonably large. So finding the parts of our application that aren't needed initially, and downloading them later can improve the initial performance of our application. And if the code is never needed, then we don't have to force the user to download it.&lt;/p&gt;

&lt;p&gt;This functionality is enabled with the import function.&lt;/p&gt;

&lt;p&gt;The import function uses quite a different syntax than the static import statement.&lt;/p&gt;

&lt;p&gt;It looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G_gKiVNH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2A9hSUjLyeYGV_Ifoa%3F" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G_gKiVNH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2A9hSUjLyeYGV_Ifoa%3F" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's go over this syntax, and what it's doing.&lt;/p&gt;

&lt;p&gt;First of all, the module path is probably the most likely place you'll get something messed up. Getting the path wrong is easy since the path has to make sense to the server. So correctly getting the path to the module set is really the biggest potential mistake. You can either give a complete path to the file, or you can give a relative path in which case the browser will assume your base URL from your current domain. Any import statement executed like this will show up in the network tab of your browser as a typical JavaScript request.&lt;/p&gt;

&lt;p&gt;Once the module has been downloaded, you now have a handle to the module itself and can do whatever you want with it in the then callback function of the promise. Note that the downloaded module is immediately parsed and executed by the browser without you doing anything. So if the code has any side effects, you can't stop them from happening.&lt;/p&gt;

&lt;p&gt;This is the mechanism used by many frameworks and libraries to download code on demand whenever needed.&lt;/p&gt;

&lt;p&gt;We use XHR calls to gather data, but we use the dynamic import function to gather additional code our project may need.&lt;/p&gt;

&lt;p&gt;The import function is used far less often than the static import statement, but it's still extremely useful to understand.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;Signup for my newsletter &lt;a href="https://thinkster.io/?previewmodal=signup?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=importfunctionvsimportstatement&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Visit Us: &lt;a href="https://thinkster.io?utm_source=devto&amp;amp;utm_medium=blog&amp;amp;utm_term=importfunctionvsimportstatement&amp;amp;utm_content=&amp;amp;utm_campaign=blog"&gt;thinkster.io&lt;/a&gt; | Facebook: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
 | Twitter: &lt;a class="comment-mentioned-user" href="https://dev.to/gothinkster"&gt;@gothinkster&lt;/a&gt;
&lt;/p&gt;

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