<?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>Forem: Peter Chittum</title>
    <description>The latest articles on Forem by Peter Chittum (@pchittum).</description>
    <link>https://forem.com/pchittum</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%2F397022%2F6eb13bdd-dc93-4803-9daf-701d4da57007.jpeg</url>
      <title>Forem: Peter Chittum</title>
      <link>https://forem.com/pchittum</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pchittum"/>
    <language>en</language>
    <item>
      <title>Go Forth, Write JavaScript</title>
      <dc:creator>Peter Chittum</dc:creator>
      <pubDate>Mon, 14 Sep 2020 12:58:47 +0000</pubDate>
      <link>https://forem.com/salesforcedevs/go-forth-write-javascript-3gpf</link>
      <guid>https://forem.com/salesforcedevs/go-forth-write-javascript-3gpf</guid>
      <description>&lt;p&gt;No small amount of ink has been spent rationalizing why JavaScript is a worthy (if not the absolute best!) language for developers to pursue. If you work as a Salesforce developer or as any enterprise software developer who has primarily worked with older technologies that abstracted the JavaScript away from the UI developer, the time has never been better to invest time and energy in learning the core language of the web.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flvszbbb5p50yed0bebal.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flvszbbb5p50yed0bebal.png" alt="JavaScript logo" width="400" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I loved server-side UI frameworks
&lt;/h2&gt;

&lt;p&gt;I was an early user of server-side generated UI technologies from the days of asp (pre dot-net), jsp, and several frameworks that were built on top of that. &lt;/p&gt;

&lt;p&gt;When I joined Salesforce in 2010, I immediately fell in love with Visualforce, the Salesforce-flavored UI framework of that era. The productivity and flexibility it gave me along with its ability to produce a custom Salesforce-looking user interface with nothing but markup was a revelation. It felt miles ahead of any other framework I had used at the time. Add to that the extensibility of business logic with the Apex programming language, and I felt there was little I couldn't do. Later Visualforce added features that allowed use of modern JavaScript frameworks and creating a powerful multipurpose foundation for custom user interfaces. From the standpoint of developer productivity as well as accessibility to coders and non-coders, I still think Visualforce had no equal at the time.&lt;/p&gt;

&lt;p&gt;But as browsers evolved and with them JavaScript, it became clear that the previous generation of server-side rendered UI frameworks was becoming less relevant. Visualforce was no exception. And although you could completely replace the server-side rendered Visualforce page with your own web framework, Salesforce began to look at a long-term solution to take forward. This solution would need to fit in this new world of JavaScript web applications. And it would need to fit in a better way than shoe-horning in a JS framework into the Visualforce container. It would also need to solve Salesforce-specific problems such as trust, security, and multi-tenancy.&lt;/p&gt;

&lt;p&gt;Enter Lightning.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Lightning difference
&lt;/h2&gt;

&lt;p&gt;Salesforce introduced their Lightning Experience user interface in 2015. With Lightning, Salesforce truly looked at rearchitecting presentation layer from the ground up, beginning with the principle that everyone builds with the same core tools. Lightning delivers on that promise. Prior to Lightning, developers on Salesforce technology teams often used one set of tools while our customers used Visualforce. With Lightning, we’re all using the same UI framework.&lt;/p&gt;

&lt;p&gt;Lightning is also a client-side framework, where you do your work primarily in JavaScript. Yes, often you will use a little bit of Apex, but the core of the work is JavaScript. With the Lightning Data Service, there are components that interact with the server where the code is exclusively JavaScript.&lt;/p&gt;

&lt;p&gt;If you can churn out traditional Visualforce with Apex controllers all day long, this will be an adjustment, but I’d argue learning JavaScript is better than ever today. In fact, we wrote a couple of great Trailhead &lt;a href="https://trailhead.salesforce.com/en/content/learn/trails/learn-to-work-with-javascript" rel="noopener noreferrer"&gt;modules&lt;/a&gt; just to help existing developers get their heads around JavaScript. &lt;/p&gt;

&lt;p&gt;Plus, there are some great benefits to adding this arrow to your developer’s quiver. Let’s take a look at some of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  NodeJS
&lt;/h2&gt;

&lt;p&gt;I start with &lt;a href="https://nodejs.org/" rel="noopener noreferrer"&gt;Node&lt;/a&gt; partially because it was a big factor in moving JavaScript from a niche language primarily for lightweight browser scripting to making it a mainstream language for tools and server-side execution. It has been on the list of Heroku-supported languages for years. But more recently, Salesforce developers should take note that &lt;a href="https://developer.salesforce.com/tools/sfdxcli" rel="noopener noreferrer"&gt;Salesforce CLI&lt;/a&gt; and the Open CLI Framework (&lt;a href="https://github.com/oclif/oclif" rel="noopener noreferrer"&gt;oclif&lt;/a&gt;) use Node. So if you want to take a stab at extending the CLI, JavaScript will be an excellent tool in your toolbox. JavaScript is also slated to be one of the first languages to be supported by the upcoming Salesforce platform &lt;a href="https://developer.salesforce.com/blogs/2019/11/introducing-salesforce-evergreen.html" rel="noopener noreferrer"&gt;implementation&lt;/a&gt; of functions as a service.&lt;/p&gt;

&lt;h2&gt;
  
  
  The ECMAScript standard
&lt;/h2&gt;

&lt;p&gt;JavaScript is based on the ECMAScript &lt;a href="https://www.ecma-international.org/publications/standards/Ecma-262.htm" rel="noopener noreferrer"&gt;standard&lt;/a&gt;. ECMAScript 6 (Often called ES6, but officially known as ES 2015) was a watershed adding language features that focused on making JavaScript a lot of fun to write, while also fixing some of its more troublesome behaviors. The ECMAScript standard continues to progress and is now in its 11th edition (ECMAScript 2020).&lt;/p&gt;

&lt;p&gt;One of my favorite features introduced in ES6 is &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment" rel="noopener noreferrer"&gt;destructuring variable assignment&lt;/a&gt;. A simple example could be you want to quickly pull out values from one or more fields in JSON that’s been returned by a server request. Let’s say it was in a variable called &lt;code&gt;obj&lt;/code&gt; that looked like 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;let&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0016E00000VNYSZQA5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Causeway, Inc.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Status__c&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Active&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might do something like 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;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Status__c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But instead you can just do 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;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Status__c&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "Causeway, Inc."&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Status__c&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "Active"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Actually, you don’t even need to settle for the names of the properties inside the JSON object. You can create your own variable names at the same time:&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;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;Status__c&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "Causeway, Inc."&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "Active"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This type of syntax will be familiar if you’ve worked with other languages. But this tiniest tip of the iceberg of modern ECMAScript &lt;a href="http://es6-features.org/" rel="noopener noreferrer"&gt;features&lt;/a&gt; bears witness to how JavaScript is actively evolving into a language you don’t just have to use, but one that many developers will really want and love to use.&lt;/p&gt;

&lt;p&gt;The great news is if you're using a modern JavaScript framework, you can use these features immediately. That includes any work you do with &lt;a href="https://lwc.dev/" rel="noopener noreferrer"&gt;Lightning Web Components&lt;/a&gt;, whether on the Salesforce platform, or in a standalone web app. &lt;/p&gt;

&lt;h2&gt;
  
  
  The JavaScript Ecosystem
&lt;/h2&gt;

&lt;p&gt;In the early days of the web, JavaScript was a minefield of different implementations, no standards, and competing APIs between browser vendors. The &lt;a href="http://jquery.com/" rel="noopener noreferrer"&gt;jQuery&lt;/a&gt; library was one of the first and by far the most popular libraries to create a unified JavaScript API that made working with the DOM browser-agnostic, and simplify asynchronous communication with the server. The combination of jQuery on the client side and Node.js on the server side supercharged the JavaScript ecosystem. &lt;/p&gt;

&lt;p&gt;Today, JavaScript is arguably the largest developer ecosystem when you measure either use, or available libraries (&lt;a href="https://blog.npmjs.org/post/615388323067854848/so-long-and-thanks-for-all-the-packages" rel="noopener noreferrer"&gt;npm&lt;/a&gt; alone has over 1 million packages and billions of downloads each month). This means it is easy to find support solving your coding problem. For instance, if you were writing a JavaScript app and wanted to integrate with Salesforce, there are a number of libraries, such as &lt;a href="https://jsforce.github.io/" rel="noopener noreferrer"&gt;JSforce&lt;/a&gt;, which is available on npm. &lt;/p&gt;

&lt;p&gt;Whether finding a library or module to abstract away a lower-level algorithm, or finding help understanding how to make use of a particular API, the JavaScript community will have you sorted. &lt;/p&gt;

&lt;h2&gt;
  
  
  Learn and practice JavaScript
&lt;/h2&gt;

&lt;p&gt;So where can you go to pick up some skills on JavaScript? The web, of course. There are no shortage of free tools, REPLs, code playgrounds, tutorials, videos, and quick starts to dive right in and learn JavaScript. But if you want to start right away, all you need to do is open your browser developer tools and start typing in the console to practice writing lines of code.&lt;/p&gt;

&lt;p&gt;For instance, try the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open this blog page (or any page) in a Chrome browser.&lt;/li&gt;
&lt;li&gt;Open up Chrome developer tools (CMD-OPT-J on Mac or CTRL-SHIFT-J on Windows).&lt;/li&gt;
&lt;li&gt;Click on console for the JavaScript console&lt;/li&gt;
&lt;li&gt;Enter the following, hitting &lt;code&gt;Enter&lt;/code&gt; after each line:

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;var newDiv = document.createElement("DIV");&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;newDiv.innerText = "JavaScript is fun!";&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;document.body.innerHTML = "";&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;document.body.appendChild(newDiv);&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;The first two lines create a new &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; element with the text of “JavaScript is fun!”. The next line wipes out all the HTML &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; of the current page. Then finally we append the new child node onto the body. At times, I have found it really useful to see how to manipulate the thing I’m working with directly to test out how code I’m working on will work.&lt;/p&gt;

&lt;p&gt;As mentioned earlier, Salesforce's learning platform, Trailhead, has some great JavaScript content. In addition to these, if you just want a taste of what Salesforce are doing with JavaScript to enable our customers to create custom UIs, try the &lt;a href="https://trailhead.salesforce.com/en/content/learn/projects/quick-start-lightning-web-components" rel="noopener noreferrer"&gt;Lightning Web Components Quick Start&lt;/a&gt;. The module &lt;a href="https://trailhead.salesforce.com/en/content/learn/modules/lwc-for-visualforce-developers" rel="noopener noreferrer"&gt;Lightning Web Components for Visualforce Developers&lt;/a&gt;, is great if you're a Visualforce expert. And if you're not a Salesforce developer and want to know how to make use of Lightning Web Components in a standalone app, check out the &lt;a href="https://trailhead.salesforce.com/en/content/learn/trails/build-apps-lightning-web-components-open-source" rel="noopener noreferrer"&gt;Lightning Web Components Open Source&lt;/a&gt; trail. &lt;/p&gt;

&lt;p&gt;Finally, fellow evangelist Josh Birk and myself collaborated on a &lt;a href="https://developer.salesforce.com/trailheadx/sessions?q=a2q3A000001pyTZQAY#tbd" rel="noopener noreferrer"&gt;session&lt;/a&gt; at TrailheaDX several years ago seeking to introduce JavaScript to developers who are experienced with Salesforce, but just beginning to learn JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping it up
&lt;/h2&gt;

&lt;p&gt;JavaScript is a critical skill today. Even in enterprise computing, JavaScript is taking a more prominent role not just in front end development, but also in other applications and tools with NodeJS. With the move to Lightning, enterprise software developers now have a great reason to invest in JavaScript expertise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://auth0.com/blog/a-brief-history-of-javascript/" rel="noopener noreferrer"&gt;Geek out on a brief history of JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Code Playgrounds&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.salesforce.com/docs/component-library/tools/playground" rel="noopener noreferrer"&gt;Lightning Web Components playground&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://jsbin.com/" rel="noopener noreferrer"&gt;jsbin&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codepen.io/" rel="noopener noreferrer"&gt;Codepen&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jsfiddle.net/" rel="noopener noreferrer"&gt;jsfiddle&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

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