Some Javascript topic You should know

Primitive Data type

Javascript has two data types. One is a primitive value and other is Reference value.

var string = 'This is a string.';
string[1] = 'A'console.log(string) // 'This is a string.'
var a = ["shakib" , "tamim" , "rakib"]
var b = a
console.log(a)//["shakib" , "tamim" , "rakib","jakir"]
console.log(b)//["shakib" , "tamim" , "rakib","jakir"]
var a = [name: "shakib" , age: 18, height : 5.9]a[0].name= 'rakib'
console.log(a)//[name: "rakib" , age: 18, height : 5.9]

typeof ()

typeof() is a function where put the data value it will be found what kind of data. What is the value of data type string, array, number boolean or undefined, you can easily get it. typeof() method.

var str = ‘hello’ ;
console.log(typeof(str)) // return string
example: var str = [‘hello’] ;
console.log(typeof(str)) // return array
example: var str = 1234 ;
console.log(typeof(str)) // return number

try-catch error handling

Suppose we have written twenty lines of codes. If Somehow code error in the fourth line, those line program will be stopped and the code will not work in the fourth to twenty lines. If we use error handling method the program easily runs if code error in any line.So try-catch has come to solve fro this problem.

console.log(alert('hello world'))
console.log(alert('hello programmer'))
console.log(alert('have a nice day'))
console.log(alert('good luck'))
try{console.log(alert('hello world'))
console.log(alert('hello programmer'))
console.log(alert('have a nice day'))
console.log(alert('good luck'))

Code Style

As a programmer, we should follow clean code style method. If you want to a good programmer you should practice how to code clean.code clean means your code looks like clean and follows the coding rules.Code will be human readable.

aligned, // 5 spaces padding at the left
another ) {
// ... }
if (   
id === 123 &&
moonPhase === 'Waning Gibbous' &&
zodiacSign === 'Libra' ){

for (
let i = 0; i < 10; i++){
if (cond) {
... // <- one more nesting level


We don't just read our code, another developer also can read. So if we code with comments it is easy to read, It will be easier for another developer. And how this code works ,it will be easy to understand when another developer sees it.But we should avoid bad comment.

// This code will do this thing (...) and that thing (...) 
// ...and who knows what else...
complex; code;
* Returns x raised to the n-th power.
* @param {number} x The number to raise.
* @param {number} n The power, must be a natural number.
* @return {number} x raised to the n-th power.
function pow(x, n) {

Arrow Function

Javascript has many functions. One method is a normal function and another is the Arrow function. I choice normal function to compare because it is easy to understand how to work the arrow function. Ok, let's follow example

//normal function
function yourName(name){
console.log('hello' , name)
//arrow function
const yourName = (name) => {
console.log('hello' , name)

Curly Brackets{}

Javascript projects curly brackets are written in the Egyptian style. If someone reads programs written in JavaScript, It should be able to read.If we use curly bracket in code our code will be clean and readable.Curly brackets are use function,conditional,objects ,destructive etc.Curly braces { } are special syntax in JSX. It is used to evaluate a JavaScript expression during compilation.


Javascript object is a another data structure where canstore multiple data. It is a reference data type.It is data collection method.Here the data is arranged in a different ways. Suppose you have student data. Here the student is an object.we can store student data name,age,roll,address etc.example:

var student1 = {name :'shakib' , age: 18 , address: 'dhaka/bangladesh'}
console.log(student1)//{name: "shakib", age: 18, address: "dhaka/bangladesh"}


The functionto to learn any programming language is one of its main thing . All languages have function.The function is nothing more than naming codeblock.If you call that name anywhere in the code later,the code block will be executed.But sometimes it is work different way on javascript.

function square(number) {
return number * number;



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