<?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: Adrian Skar</title>
    <description>The latest articles on DEV Community by Adrian Skar (@adrianskar).</description>
    <link>https://dev.to/adrianskar</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%2F121895%2F52278ba8-f244-495a-aac7-8d066fbd05a7.jpg</url>
      <title>DEV Community: Adrian Skar</title>
      <link>https://dev.to/adrianskar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adrianskar"/>
    <language>en</language>
    <item>
      <title>+ operator coerces functions into strings</title>
      <dc:creator>Adrian Skar</dc:creator>
      <pubDate>Wed, 20 Sep 2023 09:22:14 +0000</pubDate>
      <link>https://dev.to/adrianskar/-operator-coerces-functions-into-strings-53j4</link>
      <guid>https://dev.to/adrianskar/-operator-coerces-functions-into-strings-53j4</guid>
      <description>&lt;p&gt;TIL (Today I Learned) that the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition"&gt;addition operator&lt;/a&gt; coerces functions into strings. &lt;/p&gt;

&lt;p&gt;Advice: Be careful when using &lt;a href="https://javascript.info/currying-partials"&gt;currying&lt;/a&gt; and the + operator.&lt;/p&gt;




&lt;p&gt;I was reviewing the currying concept from this FreeCodeCamp's &lt;a href="https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application"&gt;exercise&lt;/a&gt; and tried to play a bit with the outputs when noticed this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Function &lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;//  6 &lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 3y =&amp;gt; z =&amp;gt; x + y + z1 ???&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I thought it should return a function or an error and tested running it on the browser and with different tools but I got the same result &lt;code&gt;3y =&amp;gt; z =&amp;gt; x + y + z1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I even asked GPT, Phind and Perplexity AI's but they, as eloquent as they can be sometimes, said that it was not possible and the correct number or an error should be returned.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sometimes you just have to get to the docs and back to basics.&lt;/strong&gt;&lt;br&gt;
Whenever the + operator finds a string or a non numeric value it'll concatenate all values as strings instead of summing them.&lt;/p&gt;

&lt;p&gt;So the breakdown of calling &lt;code&gt;add(3)(add(2))(1)&lt;/code&gt; would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="c1"&gt;// Number&lt;/span&gt;
&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;y =&amp;gt; z =&amp;gt; x + y + z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;// String&lt;/span&gt;
&lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="c1"&gt;// Number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And everything gets concatenated as one of the operands is of String type.&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;Test on &lt;a href="https://replit.com/@AdrianSkar/operator-coerces-fns-into-strings"&gt;repl.it&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.makeuseof.com/javascript-type-conversion-coercion/"&gt;Understanding Type Conversion and Coercion in JavaScript - makeuseof&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>beginners</category>
      <category>todayilearned</category>
    </item>
    <item>
      <title>Add/subtract days from date calculator</title>
      <dc:creator>Adrian Skar</dc:creator>
      <pubDate>Tue, 01 Feb 2022 17:42:43 +0000</pubDate>
      <link>https://dev.to/adrianskar/addsubtract-days-from-date-calculator-35j9</link>
      <guid>https://dev.to/adrianskar/addsubtract-days-from-date-calculator-35j9</guid>
      <description>&lt;p&gt;So I wondered when the #301DaysOfCode challenge would end because I started yesterday and built a small add/subtract days calculator. &lt;br&gt;
As it turns out you can easily "add" days to a date using &lt;code&gt;.setDate()&lt;/code&gt; but you better remember that its actual purpose is to set the day of the month rather than sum days. Both of the following options seem to work well:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"Dirty" but short:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;resultDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;days&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;"Proper" solution:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;resultDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resultDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getDate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;days&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/adrianskar/embed/vYWGyMK?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date"&gt;MDN Date&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/a/19691491"&gt;"Answer to 'Add days to [JS] Date'", StackOverflow&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Side note&lt;/em&gt;: on a terminal you can just use things like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;date&lt;/span&gt; &lt;span class="nt"&gt;--date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"301 days"&lt;/span&gt;
&lt;span class="nb"&gt;date&lt;/span&gt; &lt;span class="nt"&gt;--date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"301 days ago"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>301daysofcode</category>
      <category>100daysofcode</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Would you mentor someone 5 min. a day?</title>
      <dc:creator>Adrian Skar</dc:creator>
      <pubDate>Sat, 15 Dec 2018 14:22:16 +0000</pubDate>
      <link>https://dev.to/adrianskar/would-you-mentor-someone-5-min-a-day-1jin</link>
      <guid>https://dev.to/adrianskar/would-you-mentor-someone-5-min-a-day-1jin</guid>
      <description>&lt;p&gt;So I'm learning JS on my own and I've found many helpful sites (fCC, MDN, Dev.to...) and tools (Discord, Twitter, git, kanban boards...) but sometimes I get the feeling that I'm trying to find the perfect cherry blossom on a rainy day (not that it gets much easier on sunny ones).&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%2Fi.gifer.com%2F11aQ.gif" 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%2Fi.gifer.com%2F11aQ.gif" alt="The last samurai movie, Katsumoto looking for the perfect cherry blossom"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You have tutorials, specs, exercises and it all seems overwhelming even though you know that many things are hard to master at first and take time and effort to master.&lt;br&gt;
But, unlike learning to drive, many of us don't have an instructor or teacher to rely on and experienced people have even less free time available than us.&lt;br&gt;
So I was wondering... &lt;br&gt;
What do we do when entities can't provide the resources and means for people to learn something? How do we help a kid learn to ride a bike with no training wheels without being able to be there all the ride?&lt;br&gt;
I've seen many forum threads, groups and servers where we (as far as I'm told) ask the same questions and encounter the same difficulties when learning new programming concepts again and again. &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/http%3A%2F%2Fimoviequotes.com%2Fwp-content%2Fuploads%2F2015%2F02%2FThe-Last-Samurai-quotes.gif" 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/http%3A%2F%2Fimoviequotes.com%2Fwp-content%2Fuploads%2F2015%2F02%2FThe-Last-Samurai-quotes.gif" alt="The last samurai movie, funny kid"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And I wonder... Does this happen less on other fields?&lt;br&gt;
Can people without a teacher or mentor overcome the barrier between documentation/specs and mentorship/classroom?&lt;br&gt;
I've learned about many people trying to make better specs, people making better tools, better learning platforms and all that has brought us with many and more helpful sites and improvements, yet we're often told that one of the best ways to learn is to surround yourself of people that have more experience than you and can teach you something new. &lt;br&gt;
So, in a field where many of us are "changing" careers and don't have much free time to enjoy a meetup, attend a conference or network ourselves out of our "newbieness", how can we learn to ride a bike with no training wheels? &lt;br&gt;
Do we fall until we get it? Can we get 5 minutes a day with someone experienced to learn from directly? That doesn't seem much but... Is it fair for us to ask for 30 hours a year of someone's time?&lt;/p&gt;

&lt;p&gt;I think we're fortunate to be able to count on so many generous people and entities  that came before us and provide "free" time and resources so we all can get a chance. But, even before I call myself a developer I wonder... Can we go even further and improve our learning process without taking more from our predecessors?&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%2Fpa1.narvii.com%2F5828%2Febb625506df581cd0422f4070e241e03f4acea04_hq.gif" 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%2Fpa1.narvii.com%2F5828%2Febb625506df581cd0422f4070e241e03f4acea04_hq.gif" alt="Samurai Champloo companionship"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Side note: First time publishing anything so be gentle or hate me kindly, :) &lt;/p&gt;

</description>
      <category>dev</category>
      <category>beginners</category>
      <category>career</category>
      <category>help</category>
    </item>
  </channel>
</rss>
