2023-01-03
2639
#typescript#vanilla javascript
Ibiyemi Adewakun
107594
Jan 3, 2023 â‹… 9 min read

18 JavaScript and TypeScript shorthands to know

Ibiyemi Adewakun Ibiyemi is a full-stack developer from Lagos. When she's not writing code, she likes to read, listen to music, and put cute outfits together.

Recent posts:

Radix Ui Adoption Guide Overview Examples And Alternatives

Radix UI adoption guide: Overview, examples, and alternatives

Radix UI is quickly rising in popularity and has become an excellent go-to solution for building modern design systems and websites.

Nefe Emadamerho-Atori
Apr 25, 2024 â‹… 11 min read
Understanding The Css Revert Layer Keyword, Part Of Css Cascade Layers

Understanding the CSS revert-layer keyword

In this article, we’ll explore CSS cascade layers — and, specifically, the revert-layer keyword — to help you refine your styling strategy.

Chimezie Innocent
Apr 24, 2024 â‹… 6 min read
Exploring Nushell, A Rust Powered, Cross Platform Shell

Exploring Nushell, a Rust-powered, cross-platform shell

Nushell is a modern, performant, extensible shell built with Rust. Explore its pros, cons, and how to install and get started with it.

Oduah Chigozie
Apr 23, 2024 â‹… 6 min read
Exploring Zed, A Newly Open Source Code Editor Written In Rust

Exploring Zed, an open source code editor written in Rust

The Zed code editor sets itself apart with its lightning-fast performance and cutting-edge collaborative features.

Nefe Emadamerho-Atori
Apr 22, 2024 â‹… 7 min read
View all posts

8 Replies to "18 JavaScript and TypeScript shorthands to know"

  1. Hello !

    Thanks you for your article, I learn a lot with it.

    But I think that I found a mistake in short circuit evaluation. When you show the traditional version with if…else statement you use logical && operator but I think you wanted use logical || operator.

    I think that is just a wrting error but i prefer tell it to you.

    Have a good day

    1. I was avoiding using logical OR to make clear the explanation of short circuit evaluation, so the if statement should be confirming “str” has a valid value. I have switched the assignment statements in the condition so it is correct now.

  2. I think there is an error in the renamed variable of destructured object. Shouldn’t the line
    const {x: myVar} = object
    be:
    const {x: myVar} = obj

  3. This code doesn’t work in Typescript?
    // for object literals
    const obj2 = {
    a: 1,
    b: 2,
    c: 3
    }

    for (let keyLetter in obj2) {
    console.log(`key: ${keyLetter} value: ${obj2[keyLetter]}`);

    Gets error:
    error: TS7053 [ERROR]: Element implicitly has an ‘any’ type because expression of type ‘string’ can’t be used to index type ‘{ 0: number; 1: number; 2: number; }’.
    No index signature with a parameter of type ‘string’ was found on type ‘{ 0: number; 1: number; 2: number; }’.
    console.log(`key: ${keyLetter} value: ${obj2[keyLetter]}`);

  4. ~~x is not the same as Math.floor(x) : try it on negative numbers. You’ll find that ~~ is the same as Math.trunc(x) instead.

Leave a Reply