🎁 The Js-Craft Guide to React is now available with a 30% off discount!

Other 4 Small Javascript things I did not know until today

Some while ago I've written this article Small Javascript things I did not know until today. Meanwhile, I've discovered a few more small Js tips I would like to share with you:

1. If you have a return statement in a finally block it will overwrite other returns
function thisFunctionReturnsB() {
    try {
        throw new Error( 'Foo' );
    } catch( e ) {
        return 'A';
    } finally {
        return 'B';
    }
}

More details in this article written by Jake Archibald.

2. We can use numbers separators to improve readability
const myFirstMillion = 1_000_000;
console.log(myFirstMillion); // 1000000
3. The default case does not need to be last in a switch statement

Even if we see the default as the last option in a switch case, and somehow is also a bit logical to put it so, also the following is a valid syntax:

switch (foo) {
    case 1:
        // do something...
        break;
    default:
        // do something...
        break;
    case 3:
        // do something...
        break;
}

More details here.

Btw, you can also match multiple values in a switch statement.

4. Easily convert from a string to string to a number
const str = '404';
console.log(+str) // 404;  

Before I was using the parseInt function.

10 Javascript AI projects with Langchain & React

Not sure what to build? Dive in with these Javascript AI projects! Learn how to build LLM powered apps using Langchain.js and React! Connect your apps to LLMs such as OpenAI, create agents, use vector databases, or setup AI context.

10 Javascript AI projects with Langchain & React

Not sure what to build? Dive in with these Javascript AI projects! Learn how to build LLM powered apps using Langchain.js and React! Connect your apps to LLMs such as OpenAI, create agents, use vector databases, or setup AI context.


Leave a Reply

Your email address will not be published. Required fields are marked *

📘 The Guide to React Home Screencasts Best of Newsletter Search X

📘 - 10 Javascript AI projects with React and LangChain

Hi friend! Before you go, just wanted to let you know about the 10 Javascript AI projects ideas with React and LangChain FREE ebook.

One of the best ways to learn is by doing the work. Choose from these 10 project ideas and start working on topics such as:

  • How does LangChain work
  • Connecting to OpenAI LLM
  • Create AI Agents
  • Simple and Sequential Chains
  • Adding Memory (Chat Context)
  • Prompt Templates
  • Using OutputParsers and Tools for Agents
  • Work with Documents and more...

Keep building and see the new capabilities LLM models can add to your React app! Get all projects as an ebook right to your inbox!

X