Best JavaScript Practices
Block-level scoping

Variables and Constants

Functions and Arrow Functions

Classes and Prototypes

Destructuring

Promises and Async/Await

Block-level scoping
With JavaScript, you can define a variable or constant simply by using the var keyword. To define a block, however, use curly braces {}

For example:

`var myName = "John";` defines a variable named `myName`.

`let myAge = 24;` defines a variable named `myAge`, which has block-level scope and can be reassigned later on in the same function (if you want to).

However, if you wanted to have something that does not change during runtime and is only used within one function (like an array), then you would use const instead of let .

Variables and Constants
Variables are used to store data. They can be declared using var, const or let.

Constants are used to store data that does not change. They can be declared using const or let.

var x = "Hello"; // variable declaration with a value

const PI = 3.141592; // constant declaration with a value

var y = 2; // variable declaration without a value

let z = 4; // variable declaration without a value

Functions and Arrow Functions
Functions are mini-programs that can be used to perform actions and return values. In JavaScript, the function keyword is used to define a new function. Functions can take arguments, which are like variables that are passed into the function when it's called.

Arrow functions are a way of writing functions that is more compact than regular JS syntax. Arrow functions will be available in ES6 if you're using Babel or Typescript, and beyond ES6 if you're not using those tools (ES7/ES8).



Classes and Prototypes
A class is a blueprint for an object that determines the behavior of the object it creates.

A prototype is an existing object from which one or more new objects are created.

Destructuring
Destructuring is a way to extract multiple values from an array or object into separate variables. This means that you can take data from a larger structure, like an array or object, and pull it apart so your code looks cleaner and more readable.

Once you've learned this technique, you'll want to use it everywhere!

Promises and Async/Await
You might have heard about async/await as a new way to write asynchronous code. It’s actually not new, but it’s such an improvement that it changes the way we write our asynchronous code!

The core idea behind async/await is that it allows you to handle promises in synchronous-looking manner and make your code much easier to understand.

Async/await is a syntactic sugar which creates anonymous functions that are called immediately when they are defined (in other words, these functions don't wait for their callbacks). Then each one of those anonymous functions returns an object with two properties: value and done . Value is the actual result while done indicates whether or not there were any errors during execution. If there were errors then done will be set to false , otherwise it'll be true . For example:

async function getName() {

console.log(`Getting ${this}`);

var result = await promiseThatReturnsName();

Learn these basic JavaScript building blocks to ensure smooth programming.
Learn the basics of JavaScript, and don't worry about frameworks

Don't worry about libraries

Don't worry about tools like Babel or Webpack

Don't worry about hardware like the CPU, GPU, RAM and so on (those things are for people who want to be in computer science!)

0 COMMENTS

    There is no comments.


Please enter your comment!
Please enter your name here