Must-Know JS Syntax For React.js Developer Part — 1

Jamilur Rahman
React A-Z
Published in
2 min readOct 7, 2019
JavaScript (JS)

JS VARIABLES

Before ES6 arrived the only way to declaring variables were using var syntax. ES6 introduced some new options which provide some additional features, such as const and let.

1. const

const which is short for constant is a variable type which cannot be changed. For example, the value of pi is constant. You cannot change it. So, any variable declared with the syntax const cannot change its value. “const” can act similar to “final” syntax used in Java, C, C++, C# and other major programming languages. You can try using syntax in your browser console. You can open your console window by right-clicking anywhere in the window and select inspect element. Try out the below code in the browser console.

2. let

The “let” keyword introduces lexical scoping in JavaScript. Who come from other programming languages such as Java, Python, C are familiar with the concept of lexical scoping. For those who are not familiar with what lexical scoping is, you can think of lexical scoping as confining a variable or a part of code within a code block. For example, think of an if-else statement as a code block. In lexical scoping any variable declared within an if statement will only be accessible by that if statement. No other variable will be able to access that variable or overwrite that variable. The bellow code will demonstrate lexical scoping before and after ES6.

Default Parameters in JS

Languages such as C+ and Python allows developers to add default values for parameters in functions. These functions use these values for evaluation when triggered by an event. The below code demonstrates Default Parameters in JS.

--

--

Jamilur Rahman
React A-Z

Hi, I am Jamilur Rahman, web / android developer. I have been working with web and android frameworks for more than a year.