A good java script Programmer Need to know

Pabel Yeatun
4 min readMay 6, 2021

today i am gonna discuss 10 point about java script that’s 10 point should know as a java script programmer

1)Error handling:

as a programmer may be you are good in coding but some times we have to face error that may occur because of our mistakes or unexpected error or any other reasons,and this error may solve to take many times

but there are a syntax construct try….catch that syntax can help to fix error more quickly,this syntax has two main blocks one is try and another is catch

example:

try

{

// code…. .

}

catch (err)

{

// error handling…

}

2)data types:

two major parts i discussing about data data type, one is Primitive values another is objects and function

Primitive values:

primitive values are number ,values and many things ,all primitive values are almost same .so it does not effect in the code.

here some example are given below:

console.log(2344409);
console.log(“hello my friend”);
console.log(undefined);

objects and function:

objects and function are not primitive values, so they are not common that’s mean they are case sensitive ,object and function are effect in the code

here is example:

console.log({});
console.log([]);
console.log(y=> y* 8);

3)Comments:

a good coder always try to write comments to understand code easily ,as we know that comment have to write in single line starting with // and multiline starting with /*…../*

here is an example

/** * 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)

{

}

4)coding style:

Beginners should know about coding style.our code must be as a clean and easy so that others can understand the code easily

some programmer are take their code more complex and not much cleaning that are really hard to read.

here is the example as a clean and simple:

if (n < 0)

{

alert(`Power ${n} is not supported`);

}

Beginners sometimes don’t give a gap between curly, separate line without braces.

5)cross browser testing:

what is cross browser testing?

Cross browser testing is the practice of making sure that the web sites and web apps you create work across an acceptable number of web browsers,

as a developer we have to make sure that not only do our project that have to all our users no matter what browser or device we use ,need to think about

  • Different browsers that we use regularly on devices, including slightly older browsers that some people might still be using, which don’t support all the latest
  • Different devices with different capabilities, so need to think their capabilities

6)Var Declarations and Hoisting:

variable short form is var that are mainly use in java script.A variable can be declared after it has been used and before it has been declared. here i am giving two example:

example 1:

x = 10; // Assign 10to x

element = document.getElementById(“demo”); // Find an element
element.innerHTML = x; // Display x in the element

var x; // Declare x

example 2:

var x; // Declare x
x = 10; // Assign 10to x

element = document.getElementById(“demo”); // Find an element
element.innerHTML = x; // Display x in the element

To understand this, have to understand “hoisting”.

Hoisting is JavaScript’s default behavior of moving all declarations to the top of the current scope

7)block bindings:

for long time variable as a var are use in javascript,that are super easy but it was not without its limitations ,it’s created an issue for hosting ,so after that ES6 allows to block level declaration by introduce with let and const.

‘let’ declarations:

it gives true block level scope for our variable .this case only belongs to the for loop and can only be used within that scope

example:

function fun1()

{

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

{

let num = 10;

}

console log(num);

}

The num variable in this case only belongs to the for loop and can only be used within that scope

‘const’ declarations:

const’ declaration variables can not be modified once they have been initialized.this are threated as a block level variable

const pi = 3.1416;

pi= 6; //error

8)Default parameters:

Default parameters also called named parameters that are initialized with default values if no value or undefined is passed.

function multiply(a, b = 1) {
return a * b;
}

console.log(multiply(5, 2));
// expected output: 10

console.log(multiply(5));
// expected output: 5

function parameters default as a undefined . it's often useful to set a different default value.

9)Spread syntax :

Spread syntax allows as an array expression or string to be expanded in places where zero or more arguments or elements are expected,

function sum(x, y, z) {
return x + y + z;
}

const numbers = [2, 3, 4];

console.log(sum(…numbers));
// expected output: 9

console.log(sum.apply(null, numbers));
// expected output:

here the defined function takes x, y, and z as arguments and returns the sum of these values. An array value is also defined.here pass all values in the array using spread syntax

10)Arrow function expressions

An arrow function expression is a limited and can’t be used in all situations.its also a compact alternative to a traditional function expression,

Differences & Limitations:

  • Does not have this or super, and should not be used as methods
  • Does not have arguments or new.target keywords.
  • Not suitable for call, apply and bind methods,
  • Can not be used as constructors.
  • Can not use vield

const materials = [
‘rahim’,
‘karim’,
‘salim’,
‘momin’
];

console.log(materials.map(material => material.length));
// expected output: Array [8, 6, 7, 9]

--

--