7 Cool Useful JavaScript Coding Techniques That You Should Use
<h1>1. Initialize the array with “fill”</h1>
<p>Initialize an array of a fixed length and each item is “fatfish”.</p>
<p><iframe frameborder="0" height="171" scrolling="no" src="https://fatfish.medium.com/media/9a80faa29c5cd5597efc7f9dbeba9b04" title="fill.js" width="680"></iframe></p>
<p>Actually, using <code>fill</code>, it will be very easy.</p>
<p><iframe frameborder="0" height="83" scrolling="no" src="https://fatfish.medium.com/media/eb9f6e4782a40e13c5e5ac15ba52eaac" title="fill2.js" width="680"></iframe></p>
<h1>2. Use object instead of “switch”</h1>
<p>We often use <code>switch</code> to handle different things, but have you ever thought of using an object to greatly simplify your code?<strong>(It works in some simple scenarios)</strong></p>
<p><iframe frameborder="0" height="369" scrolling="no" src="https://fatfish.medium.com/media/a8cd0f9d29bd725d49a62a2e4f4e6818" title="switch.js" width="680"></iframe></p>
<p>You only need to use an object to achieve your goal.</p>
<p><iframe frameborder="0" height="215" scrolling="no" src="https://fatfish.medium.com/media/8c867c7a4aff786d86f80f98c1c4e9ad" title="switch2.js" width="680"></iframe></p>
<h1>3. Use “? … : …” instead of “if… else…”</h1>
<p>Many times simple conditional judgments do not need to use “if”.</p>
<p><a href="https://fatfish.medium.com/7-cool-useful-javascript-coding-techniques-that-you-should-use-68d36bace056">Website</a></p>