DEV Community


Javascript all you need to know

Taieb Hossain
・3 min read

Arrow Function:
Arrow Function first introduce in ES6. This makes it easier to write a function shortly than a regular function. It's get's more shorter if the function has only one statement.
const sum = (x, y) =>{
return x + y
Example2: const double = val => 2 * val;

Var declarations: - In javascript, you can declare a variable in three ways.
i) Var - var is the oldest way to declare a variable.
ii) Let - In 2015 javascript ES6 version introduced let. If you want to declare a variable that will only accessible in a specific block of code, then let is perfect.
iii) Const - In ES6 const is the other that introduced. Const means constant. If you have a variable that you won't change then const is suitable for you. Because After declaring a variable with const you can't change that variable.

Block Level Declaration: - The javascriptES6 Let keyword offers block-level declaration. In the past variable declared with var can be accessed outside the block of code or function. But with let variables cannot be accessed outside the {} block or a function.

Spread Operator: - In simple spread means to expand or stretch a compact thing. The javascript spread operator expands something to better use. Thin you have two arrays and you want only one array with all items of these two arrays. You can do that in various ways but with a spread operator, it will be very simple to do. See the example below
const num1 = [1,2,3,4,5]
const num2 = [6,7,8,9,10]

const allNum = [...num1,...num2]

Try- Catch: - Error is the part of a developer or a programmer's life. Without knowing try and catch no one can be a good developer. Inside try block, executable code be there and if any error happens what should you do, there comes to catch, catch block catches the error when any type of error happens, the error goes to catch block. Simple example -

try {
console.log("Hello world")
// code to be executed

Comments: - Commenting in the code is a good thing. But everything has a limit. Too many comments are bad because they totally changed the look of the code. Comment should be the summary of the code that what's going on not to be the description

Code Style: - There are no mandatory style rules for writing codes. It's just a convention or like preference to look better, understand better. There are many style rules in the programming world everyone has their own preference. If you write a code that works well but not clean or hard to understand what's going on in the code. Then this is useless. Here comes code style. See the example below... and then told me which one is better,

let num=2;


let num = 2;

if(num = 2) {
console.log(2 * 100)

Data Types: - Not only javascript in all programming languages data type is a very important concept. In javascript, primary data types are string, number, boolean, null, and undefined.

Function With Default Parameter: - By default function parameter value is undefined. When you call the function without passing the argument function will return the value undefined. But if you don't pass any argument and also don't show the result undefined you can set the parameter default value. Example below:

function person (firstname= "John", lastname = "Sina"){
// expected result John, Sina,

Event Loop:- The javascript event loop is simply the execution of code one by one asynchronously. Because javascript is a single-threaded programming language that can do only one thing at a time. When an event happens that goes to the stack

Discussion (0)