Types

Every language has some primitives types. And JavaScript also has some. There are six primitives types in JS.

  1. String,
  2. Number,
  3. Undefined,
  4. Null,
  5. Boolean,
  6. Symbol.

That’s important to know about the primitives types. Because it helps a lot to understand the language.

console.log(“Hello”)//String

console.log(3)//Number

console.log(undefined)//Undefined

Expressions

JavaScript’s language syntax recognizes expressions and statements. Both are different and we should need to know the basic difference.
An expression is a code that evaluates the value and a statemnet is a code that performs.
console.log(2 + 2);//expression
if (answer !== 1) { answer = 1} // statement

Checking a type of value:

: Who are you?

:: My name is Bond. James Bond.

If you ask you will get an answer. Just you need to ask. JavaScript is a good boy. If you ask him “What type of value is that?”. He will give you the answer. Just you need to know how to ask. So, we will use Expressions called typeof. And obviously, he will give you the answer.

console.log(typeof 75); // expected output: “number”

console.log(typeof ‘Shakib Al Hasan’); // expected output: “string”

console.log(typeof true); // expected output: “boolean”

console.log(typeof undeclaredVariable); // expected output: “undefined”

Error Handling:

:: “I’m not a robot”.

This is the most annoying exam to prove that I’m a human being. So I’m a human being. I make mistakes. Sometimes I find those mistakes and try to solve it. But When I’m a programmer, maybe I make mistakes, but every time I need to find it and solve it. In JavaScript, Mr. Finder will help us to find the error. try..catch our Mr.Finder in JavaScript. By using this syntax the error can be handle.

try {

// code…

}

catch (err)

{

// error handling

}

try will run the code, if there is no error then catch block will ignore otherwise catch block will execute.Some note about try..catch

  1. This will work only when the script is valid.
  2. This syntax must be used inside a function

Coding Style:

A beautiful road can help you to walk a mile. A beautiful environment can make your mind fresh. An organized table can increase your learning willing. Beautification is everything.

Beautification in programming is also important. When we write a code we need to try to make it clear, fresh. There are no fixed rules to maintain the way to beautify a code. But if we follow some steps and ideas that can help another programmer to understand the functionality.

  1. No space between the function name and parentheses between the parentheses and the parameter.
  2. A space between parameters
  3. Curly brace { } on the same line, after space.
  4. Indentation 2 space for the new line after the function
  5. Space after statement
  6. Use semicolon is mandatory
  7. An empty line between logical blocks
  8. Spaces around a nested call

Comments in code:

Imagine yourself in an area without a nameplate, without holding, without a location card. How do you feel? No good.

Or imagine that you write 1000 lines of code the whole night, and after that night when you open your code you don’t know which function is used for what operation.

Or imagine your junior developer messaged you to help him out from an error in his code. But when you open the code you cant understand that what is used for what operation.

So, what is the solution? Comments. Basically, comments use to describe how and why the code works. how to comment? when we comment a single line it starting with // and for multiline we use this /* … */. Keyboard shortcuts ctrl+/

ECMAScript or ES6

ES6 alludes to form 6 of the ECMA Script programming language. ECMA Script is the normalized name for JavaScript. It was released in 2011. it represents a scripting language specification called ECMAScript.

Block-level Declaration

After ES6 is released we can declare the variable with let or const. const are values that can be characterized just a single time. And let is work like var.

const pi= 3.1416; //constant

let x = ‘“hello”;

Arrow Function in ES6:

ES6 introduced arrow function in JS. For a lot of opportunity I personally like the new feature of ES6 is arrow function. There are two significant advantages of utilizing Arrow functions. One is that it’s a more limited syntax and hence requires less code. It cant be used in all situation.

traditional function:

function (x,y){

return x+y;

}

arrow function:

(x, y) => x + y;

How JavaScript Run

JavaScript is what is known as a Client-side Scripting Language. That implies that it is a PC programming language that runs inside an Internet program. The manner in which JavaScript works is interesting. Inside a typical Web page you place some JavaScript code . At the point when the program stacks the page, the program has a built-in interpreter that peruses the JavaScript code it finds in the page and runs it.

JavaScript is divided into two memory in it

  1. Heap Memory,
  2. Stack Memory

Memory Heap is where the memory allocation happens. Call Stack is where your stack frames are as your code executes.