CodeblogBlogBooksResources

Using TC39

05 May, 2020 - 8 min's read

Hi, today I want to share for you some interesting things about development innovations in JS. So, I often use some new innovations in javascript, it's help me to save the time. This blog I dedicated to TC39.

πŸ“’ What is TC39?

TC39 - it's technical committee ECMAScript which considers proposals in JS. This process has five different stages to get the specification live:

  • Stage 0: Strawperson β€” to allow input into specifications
  • Stage 1: Proposal β€” make the case for the addition, describe the solution and identify the potential challenges
  • Stage 2: Draft β€” describe the syntax and semantics using formal spec language
  • Stage 3: Candidate β€” states that further refinement will need feedback from implementations and users
  • Stage 4: Finished β€” states that the addition is ready for inclusion in the formal ECMAScript standard

πŸ’Ό Last useful proposals for me

Some last useful finished proposals which save time:

So, we use Optional Chaining operator for omit check if field exist. It can work with DOM API.
In a bundle, it transpile to chain of conditions. If field does not exist operator return undefined.

Example:

const object = {
    someFields: {
        anotherFields: {
            ...
        },
    }
};

// Error: Uncaught TypeError: Cannot read property 'anotherFields' of undefined
console.log(object.unknownFields.anotherFields);

// Return undefined
console.log(object.unknownFields?.anotherFields);

So, it's operator can you set default value if your variable is null or undefined without typecasting.

Example:

const response = {
  settings: {
    nullValue: null,
    height: 400,
    animationDuration: 0,
    headerText: '',
    showSplashScreen: false
  }
};

// Return 'some other default'
const undefinedValue = response.settings.undefinedValue ?? 'some other default';

// Return 'some other default'
console.log(response.settings.nullValue ?? 'some other default');

// Return ''
console.log(response.settings.headerText ?? 'Hello, world!');

// Return 0
console.log(response.settings.animationDuration ?? 300);

// Return false
console.log(response.settings.showSplashScreen ?? true);

πŸ“ Notes

For using it in old browsers you need a polyfill. More details.


πŸ”— Links

You can ask questions in the comments. Thanks for reading this article!

Codeblog Β© 2020