Web Tools Weekly
What a Tool!

Issue #228  (const, Uncats, JS Utils, React Tools)11/30/17

I'm sure by now you've seen posts and examples of code that use ES6's new const statement, for declaring constants. For a succinct summary, here is a run-through of the basics regarding const.

A const cannot be changed after it's initialized. In other words, this will throw an error:

const example = 'Hello';
example = 'Bonjour';
// Error: Assignment to constant variable.

Also, you can't repurpose a let or var variable as a const, so you'd get an error in that case too (e.g. if the "example" variable was defined using var, then defined again using const).

You cannot initialize a const without defining a value. This will also throw an error:
const example;
// Error: Missing initializer in const declaration

Constants, like let declarations, are block scoped. This means they aren't accessible outside of the block in which they're declared. This is one of the ways that let statements improve on var, and this is identical in const.
if (true) {
  var example = "Hi";
  const example2 = "Hello";

console.log(example); // "Hi"
console.log(example2); // Error: example2 is not defined

As shown in the example above, the const declaration is not hoisted so it's not accessible outside the if block. And note that you can use const to initialize a variable in a for loop, as long as the loop doesn't modify the value of the const.

Although a const declaration can't be changed after it's initialized, an object declared as a const can be modified. For example, this is valid:
const example = {
  one: 'Hello'

console.log(example.one); // "Hello"

example.one = 'Hi';
console.log(example.one); // "Hi"

Using the above code, it's the value of "example" that can't be altered, not the values of properties within the object itself.

Finally, as a best practice recommendation: Use const as the default, unless you know that the value is intended to change; then use let. This is different from what most developers might have assumed, which is to use let to replace var. You should use const to replace var as long as you know the value is not intended to change.

More info on const on MDN and lots of credit to Nicolas Zakas' Understanding ECMAScript 6 for his great coverage of this and other ES6 topics.

Now on to this week's tools!
Did you buy my previous JavaScript/DOM tips book? Here's the latest one...
70 JavaScript & DOM Tips for $5 (Volume 2)

The Uncategorizables

A front-end URL shortener without a database. Using a script tag, adds a shortener to your site based on your own domain.

Tripetto Forms
A new way of creating and deploying forms in websites and applications.

HTML to PDF conversion API.

An API documentation generator for JavaScript.

Collect info from users without a server—Pageclip is your server. Lead capture forms, surveys, newsletter forms, contact forms, etc. Setup any form in seconds.

Sketch Syntax Highlighter
Sketch plugin. Automatically highlight the syntax of any code snippet, right inside Sketch.

Sandcat Browser
Web browser targeted at people who test websites for security holes, developers, or anyone else wanting more low-level control over browsing.

Style Guide Guide
A boilerplate for creating style guides.

JavaScript Utilities

A small, lightweight library for working with currency values. Built to work around floating point issues in JavaScript.

Virtual syntax highlighting for virtual DOMs and non-HTML things, with language auto-detection. Perfect for React, VDOM, and others.

Redux Zero
A lightweight state container based on Redux.

Slim Select
Slim vanilla JavaScript HTML select dropdown component.

A 188b/253b spreadsheet app (Excel clone) in HTML and JavaScript.

Pipes values through functions, an alternative to using the proposed pipe operator ( |> ) for ES.

Slack JS
Slack API client for Node and browsers.

A library to make functions support both callback and promise styles.

A really old, but interesting, project. A JavaScript/CSS component to add a full-screen option for typing into a textarea element.

Do you like this newsletter? Here's an option to show your support...
Make a One-time Donation via PayPal.me/WebToolsWeekly

React Tools

A state management library for React applications and is extremely simple to use.

A smart popover component with animation support for React.

A collection of imperative Browser APIs turned into declarative React components and higher-order components for lots of common situations.

React-based drag-and-drop pivot table with Plotly.js charts. You can demo it live on the home page with CSV data or CSV file.

React Transition Group
An easy way to perform animations when a React component enters or leaves the DOM.

React Accessible Accordion
Accessible accordion component for React.

React Reveal
A dead simple way to add reveal-on-scroll animations to your React app. Less than 2kb gzipped and written for React from scratch in ES6.

An input component for picking dates for your React application.

Build forms in React, without the tears. Makes testing, refactoring, and reasoning about your forms a breeze.

A Tweet for Thought

Peter-Paul Koch discusses "the most serious problem we have in front-end right now."

Suggestions / Corrections

Made something? Send links via Twitter @WebToolsWeekly (details here). No tutorials or articles, please. If you have any suggestions for improvement or corrections, feel free to reply to this email.

Before I Go...

If you like card games and/or board games, you might be interested in Stock Against Photography.

Thanks to all for subscribing and reading!

Keep tooling,