OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Is Babel used to produce backward or forward compatible Javascript code?

  • Thread starter Thread starter Zerro97
  • Start date Start date
Z

Zerro97

Guest
I have been reading through a book called You don't know JS and one thing that I can't wrap my head around is the concept of backward compatible and forward compatible Javascript.

From what I understand:

  1. Backward Compatible: Once something is added to Javascript specification, it would never become invalid JS in future
  2. Forward Compatible: Including a new addition to the language in a program would not cause that program to break if it were run in an older JS engine

Javascript is backward compatible and not forward compatible. This means that while including new feature in a program might break the program (forward compatible), Javascript engines would support older syntax forever in future (backward compatible).

To solve a problem of forward compatible issue, developers use transpilation and polyfills to convert new syntax to an older syntax supported in older Javascript engine.

So if transpilation is used to convert code into forward compatible code, does that mean Babel is used to solve forward compatibility issue and not backward compatibility issue?

This comes from the official doc in Babel website:

Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments.

I must have missed something and need some clarification on how to think through this.

Edit 1

I thought it would be helpful to quote parts of the book here:

Typically, forwards-compatibility problems related to syntax are solved by using a transpiler (the most common one being Babel (https://babeljs.io)) to convert from that newer JS syntax version to an equivalent older syntax.
Developers should focus on writing the clean, new syntax forms, and let the tools take care of producing a forwards-compatible version of that code that is suitable to deploy and run on the oldest-supported JS engine environments.

<p>I have been reading through a book called <a href="https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/get-started/ch1.md" rel="nofollow noreferrer">You don't know JS</a> and one thing that I can't wrap my head around is the concept of backward compatible and forward compatible Javascript.</p>
<p>From what I understand:</p>
<ol>
<li><strong>Backward Compatible:</strong> Once something is added to Javascript specification, it would never become invalid JS in future</li>
<li><strong>Forward Compatible:</strong> Including a new addition to the language in a program would not cause that program to break if it were run in an older JS engine</li>
</ol>
<p>Javascript is <em>backward compatible</em> and <strong>not</strong> <em>forward compatible</em>. This means that while including new feature in a program might break the program (forward compatible), Javascript engines would support older syntax forever in future (backward compatible).</p>
<p>To solve a problem of forward compatible issue, developers use <strong>transpilation</strong> and <strong>polyfills</strong> to convert new syntax to an older syntax supported in older Javascript engine.</p>
<p>So if transpilation is used to convert code into forward compatible code, does that mean Babel is used to solve forward compatibility issue and not backward compatibility issue?</p>
<p>This comes from the <a href="https://babeljs.io/docs/en/" rel="nofollow noreferrer">official doc</a> in Babel website:</p>
<blockquote>
<p>Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a <strong>backwards compatible</strong> version of JavaScript in current and older browsers or environments.</p>
</blockquote>
<p>I must have missed something and need some clarification on how to think through this.</p>
<p><strong>Edit 1</strong></p>
<p>I thought it would be helpful to quote parts of the book here:</p>
<blockquote>
<p>Typically, forwards-compatibility problems related to syntax are solved by using a transpiler (the most common one being Babel (<a href="https://babeljs.io" rel="nofollow noreferrer">https://babeljs.io</a>)) to convert from that newer JS syntax version to an equivalent older syntax.</p>
</blockquote>
<blockquote>
<p>Developers should focus on writing the clean, new syntax forms, and let the tools take care of producing a <strong>forwards-compatible</strong> version of that code that is suitable to deploy and run on the oldest-supported JS engine environments.</p>
</blockquote>
 

Latest posts

Top