A little bit of JavaScript, Cache, and Testing

Raghib Ahsan
3 min readNov 3, 2020

JavaScript errors try. catch.

When we write code sometimes it gives the wrong output. It may be programmer faults or machines fault or other reasons. But we have to handle this error. To handle this try-catch is one method. When the code in the try block is executed, if there is no error then it ignores the catch block and gives the output. Otherwise, a catch block code will be executed.

Syntax of writing function

When we are going to write write a function, three are contained parameters, statements. There have to space between parameters. Indentation 2 space beginning of the line. At the end of the line, a semicolon is mandatory.

Comments

A single comment starts with // and multiple comments start with /* and end with */. Basically, comments are written to explain the code. So when the other persons see the code they can easily understand it.

Primitive value

All numbers and strings are primitive values. And also boolean, null, undefined, and bigInt types are primitive values.

Default function parameter

The default function parameter allows initializing a function with default values if the arguments are not supplied to the function call. In the below program parameter a and b default value 1. But if b isn’t initialized with the default value then the second output is Nan. Because we take two parameters but give only one value. So the output is Nan

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

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

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

Arrow function

This the simple way for creating function. It is easier than function expression. (a, b) => a + b; means a function that accepts two arguments named a and b. The expression a+b and returns the result.

// Regular function

let sum = function(a, b) {

return a + b;

};

//Arrow function

let sum = (a, b) => a + b;

Spread Operator

… is spread, operator. The simple way to describe it is to copy the value or data of variables.

// spread operator for copying
let arr = [‘a’,'d’,’c’];
let arr2 = […arr];

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

arr2.push(‘d’); //inserting an element at the end of arr2

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

Caching

Caching is the process of storing copies of files in a cache. It is temporary local storage. It stores data for a certain time so that can be accessed quickly. Web browsers cache HTML files, JavaScript, and images to load websites more quickly. When we browse the internet there some data are saved in local storage that is cache.

Cache server

A cache server is a dedicated network server that saves Web pages or other Internet content locally. Users can access content offline by it. It is also called the cache engine. It is also commonly used as a proxy server.

Cross-browser testing

It is one kind of testing that checks whether a website works when it is accessed through different browser-OS combinations, different devices, assistive tools. By testing it we can know what is wrong and be able to fix it, to enhance efficiency and user experience and business.

--

--