programs Error😂 — JavaScript

Shahinur islam
3 min readMay 6, 2021

01.Primitive values:

primitive (primitive value, primitive data type) is data that is not an object and has no Method. There are 7 primitive data types.

  1. Yes or no (a boolean).
  2. My age (a number).
  3. My name (a string).
  4. Nothing at all (undefined).
  5. A doodle or anything else which means nothing to me at all (null).
  6. Numeric data type(BigInt)
  7. symbol

Example:

// Using a string method doesn’t mutate the string

var myName = “shahinur”;

console.log(myName); // shahinur

myName.toUpperCase();

console.log(myName); // shahinur

// // Using an array method mutates the array

var simple = [];

console.log(simple); // []

simple.push(“wow”);

console.log(simple); // // [“simple”]

02.Error handling, “try…catch”

we are at programming, sometimes our scripts have errors.They may occur because of our mistakes, unexpected user input, an erroneous server response, and for a thousand other reasons.

The try…catch syntex

try {

// code…

}

catch (err) {

// error handling

}

  1. First, the code in try … () is executed.
  2. If there were no errors, then catch (err) is ignored: the execution reaches the end of try and goes on, skipping catch.
  3. If an error occurs, then the try execution is stopped, and control flows to the beginning of catch (err). The err variable (we can use any name for it) will contain an error object with details about what happened.

03.Comments

JavaScript comments can be used to explain JavaScript code, and to make it more readable. and javaScript comment purpose used for helping my codding category divided comment. its browsers don't open this comment line code.

Comments two types comments can be single-line: starting with // and multiline line comment : /* ... */.

Single line comment Example

var x = 5; // Declare x, give it the value of 5
var y = x + 2; // Declare y, give it the value of x + 2

Multiline line comment Example

/*
document.getElementById(“myH”).innerHTML = “My First Page”;
document.getElementById(“myP”).innerHTML = “My first paragraph.”;
*/

04.Block Bindings

What is Binding?

Variable is more formally known as binding. we actually bind a value to a name inside a scope.

Example

we use var, let, and const to declare or assign a variable.

var a = 1
let b = 2
const c = 3

Var Declarations and Hoisting

var declarations global scope and enclosing block

05.Functions with Default Parameter Values

ES6 makes it easier to pass default parameter values when the parameter is not formally passed when calling the function. For example:

function sum(num1, num2 = 0) {
return num1 + num2
}
console.log(sum(30, 5)) // 35
console.log(sum(50)) // 50

06.The Spread Operator

What is Spread Operator:

The spread operator is a new addition to the set of operators in JavaScript ES6.In the above syntax, is a spread operator which will target all values in a particular variable. When … occurs in the function call or alike, it's called a spread operator. Spread operator can be used in many cases, like when we want to expand, copy,concat, with math object. Let’s look at each of them one by one:

Syntax:

var variablename = [...value];

spread operator Expressions:

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

const numbers = [1, 3,5 ];

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

07.Arrow Functions

What are Arrow functions?

Arrow Functions — also called “fat arrowfunctions, are relatively a new way of writing concise functions in JavaScript

Why arrow functions are used?

Arrow functions intend to fix the problem where we need to access a property of this inside a callback. There are already several ways to do that: One could assign this to a variable, use bind, or use the third argument available on the Array aggregate methods.

When are arrow functions used?

Arrow functions shine best with anything that requires this to be bound to the context, and not the function itself.

Despite the fact that they are anonymous, I also like using them with methods such as map and reduce, because I think it makes my code more readable. To me, the pros outweigh the cons.

08.Block Binding in Loops:

1.Inside of a function
2.Inside of a block { \\code block }

Let Declarations
The let declaration syntax is the same as the syntax for var. You can basically replace var with let to declare a variable, but the limit is only the current code block. Here’s an example:

function getValue(condition) {

if (condition) {
let value = “blue”;

// other code

return value;
} else {

// value doesn’t exist here

return null;
}

// value doesn’t exist here
}

09.Global Block Bindings:

10.Unnamed Parameters:

--

--