JavaScript Data Types, Error Handler, Function, ES6

Shohelrana Baig
4 min readNov 3, 2020

1. JavaScript Data Types:

There are 2 types of data types in JavaScript. They are -

→Primitive Data Types.

→Non-primitive Data Types.

→Primitive Data Types:

There are seven types of primitive data types. they are-

  • Undefined — it represents undefine value. it used foe unintentionally missing value.
  • Null — it represents null value. it used for intentionally missing value.
  • Booleans — it performs boolean value true or false. it used for logical operations.
  • Numbers — it represents numerical value. it used for math calculations.
  • Strings — it represents character. it used for text. example (“ hi’ ,“shohel” ).
  • Symbols — it perform for unique identifiers, to hide implementation details.
  • BigInts — it performed for math on big numbers.

→Non-primitive Data types:

There are three types of non-primitive data types. they are-

  • Objects — it is performed to group related data and code.
  • Functions — it is performed to refer to code.
  • Arrays — it is performed for group of similar values.

2. Error Handling(try…catch):

Error handling is the routines in a program that responds to abnormal input or conditions. Basically, (try…catch) is used to handle the error part of the code.

“ try…catch ” syntax:

try {

expression; //code to be written.

} catch ( err ) {

expression; //code for handling the error.

}

it works —

  • First, the code is try {…} is executed.
  • if there are no errors, then catch(err) is ignored.
  • if an error happens then the try execution is stopped and control flows to the begging of catch(err). the err variable will hold an error object with details about what happened.

Example:

try {

alerting ( “it is a lovely day” );

} catch ( err ) {

console.log ( err );

}

3. Cross Browser Testing:

Cross browser testing includes comparing and analyzing the behavior of your website in different browser conditions.

Workflows for cross browser testing:

Initial planning > Development > Testing/discovery > Fixes/iteration.

4. Var Declarations and Hosting:

Variable declarations using var are used as if they are at the top of the function thoughtless of where the actual declaration occurs, this is called hoisting. the following function definition:

If you are unfamiliar with JS, then you might expect the variable value to only be created if condition appreciate to true. the JavaScript engine changes the getValue() function to look like this example:

5. Block-Level Declarations:

Block Level Declarations are the ones which declare variables that are far outside of a given block scope. Block Scopes also named lexical scopes. Block scopes are created either inside of a function or inside of a block ( indicated by the { and } characters) .

6. Block Binding in Loops:

This is area where block level scoping of variables is within for loops where the throwaway counter variable is meant to be performed only inside the loop. Follow the two examples:

for ( var i = 0; i < 10; i++ ) {

process ( items [i] );

}

//i is still accessible here

console.log ( i ); //10

The variable is still accessible after the loop is completed because the var declaration gets hoisted, using let instead-

for ( let i = 0; i < 10; i++) {

process ( items[i] );

}

//i is not approachable here — throws an error

console.log( i );

this example, the variable i only exists within the for loop.

7. The Spread Operator ( … ):

The spread operator is a operators in JavaScript ES6. Spread operator allows an iterable to expand in places where 0+ arguments are expected. it is used in the variable array where there is more than 1 values are expected. Syntax of Spread operator is same as Rest parameter but it works opposite of it.

Syntax:

var variableName = […value];

Example:

let array = [ ‘a’ , ‘b’ ];

let array2 = [ …array , ‘c’ , ‘d’ ];

console.log( array2 ); // [ ‘a’, ‘b’, ‘c’, ‘d’ ]

8. Arrow Functions:

Syntax: hello = ( ) => “hello world!”;

After ES6 we can write:

Example-1: (Arrow function one parameter)

Example-2: (Write more statement after arrow)

9. Function Default parameter:

Example_1: first way:

Example_2: second way ( ES6_Update)

10. Block-Level Functions:

ES6 supports the block-level functions so the given code should produce the error “doSomething is not defined”.

Example:

--

--