JavaScript Concept

1. JavaScript data Types

There are six basic data types in javaScript that are main three part such as

· Primitive data types: String, Number and Boolean

· Composite data types: Array, Object and Function.

· Special data types: Undefined and Null

2. Error handling “try and catch”

How to work try and catch in javaScript ->

· First, run the code in browser

· If the code is work, try is work and ignore catch

· If the try don’t work or ignore, as a result catch is work and show error in ui.

Example:

try {

alert(‘successfully reload”)

} catch{

alert(“something wrong”)

}

If the code is work, ui show successfully reload, but code not working, ui show something wrong.

3. JavaScript comments

JavaScripts has two type of comments such as,

· Single line comments

· Multiple line comments

Below the example:

Single line comments

// this is the example in code

<h1>I am a student </h1>

Multiple line comments

/**

*multiple line comments here

*allah might help me

**/

4. JavaScript Arrow function

Arrow function is using in lieu of function(). Arrow function is a ES6 related function.

For example arrow function:

const friends = [

{

Name: “Boni”,

Profession: “Marketer”,

Age: 22

},

{

Name: “Hafiz”,

Profession: “Web Developer”,

Age: 23

},

{

Name: “Monir”,

Profession: “Banker”,

Age: 21

}

]

const friendsLength = friends.map(friend => friend.length)

console.log(friendsLength)

Output result = 3

5. JavaScript default parameters

JavaScript default parameters is allow to initialize named parameters with default parameters if no valus or undefined in passed the function

How to handle default parameters in JavaScript

For example:

function adding(x, y){

return x + y

}

const total = Adding(100, 200)

console.log(total)

Get output = 300

6. JavaScript Spread Syntax

Spread syntax is using when copy of the all elements in object or array and add new items this object or array.

For example:

const fruits = [“banana”, “apple”, “mango”]

const addFruits = […fruits]

addFruits.push(“lemon”)

result = [“banana”, “apple”, “mango”, “lemon”]

7. New feature in ES6

let and const are alternative to var declaration

For example:

var num = [1, 2, 3, 4]

let num = [1, 2, 3, 4]

const num = [1, 2, 3, 4]

Those are same. If you use let, you will change in code again and again but if you use const, you won’t change code again and again

8. JavaScript coding style

Code style must be clean that a programmer easy to read and understand as possible.

This is the art of coding. If the code is not clean, a programmer will not read the code, as a result he can’t solve the codeing problem. So, must be code clean.

9. Block Level declaration

The new ES6 specification let and const that takes inside the function but var not allow .

For example:

function func1()

{

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

{

let tmp = 10;

}

console.log(tmp); // would result in an error

}

10. Type of values

A programmer must know about value. Because this the core concept of javaScript

Primitive values:

· Null: used for missing values

· Undefined: also used for missing values.

· Booleans: used for condition

· Number: used for math calculation

· String: used for text

· Symbols: used for hide details

· BigInts: used for math on big numbers

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store