A brief discussion on JavaScript

Faisal Ahmed
4 min readMay 6, 2021

--

Javascript is a very popular programming language. It is one of the most popular scripting languages at the current time. Javascript is a dynamic type language, if programmers make any variable, and without writing the type javascript will understand the type of variable. Popular companies of recent times like PayPal, Netflix, Groupon, Uber, Facebook, Google use javascript. So to grow as a developer we need to learn javascript. This article will discuss more topic which will help the developer to grow as a javascript developer.

Objects

In javascript objects are refers as collections of property. A property is a collaboration of name and value. An example is given below:

 
var student1 ={id:121,phone:1745,name:”John”}
var student2 ={id:221,phone:1746,name:”Kabir”}var phoneNo= student1.phone;console.log(student1);console.log(student2);console.log(phoneNo);
//output :{ id: 121, phone: 1745, name: 'John' }
{ id: 221, phone: 1746, name: 'Kabir' }
1745

there are two objects one is student1 and student2 have three property collections. Property has three names and values. We can individually access any name and can access its value

Functions

Javascript functions are block code that executes a particular task assign by the programmer. A function is executed when it called. Functions help a programmer from repeating a coding again and again. An example of a function is given below:

function hello (){
console.log("hello everybody")
}
hello();
//output: hello everybody

Here is a function named hello. In the functions, we write hello everybody. To Execute the function we call the function. We must have to call a function to execute. Wherever we need the function we just have to call the function.

Style Guides

In any programming language, there is a style guide to maintain. It actually keeps the code clean and simple. A style guide helps the programmer to write a programmer in a manner so that other programmers can understand the code of a particular language. There is some popular javascript style guides name given below:

Google JavaScript Style Guide

Airbnb JavaScript Style Guide

Idiomatic.JS

Standard.JS

Line Length

In programming language programs are written in a vertical manner. It is a universally accepted system to write code vertically, not horizontally. JavaScript also follows that rule. Line length depends upon the team’s decision usually between 80 or 120 characters.

let moon= `  The Moon is Earth's only natural satellite. At about one-quarter the diameter of Earth, it is the largest natural satellite in the Solar System relative to the size of its planet, and the fifth largest satellite in the Solar System overall`;console.log(moon);
//ouput: The Moon is Earth's only natural satellite. At about one-quarter the diameter of Earth, it is the largest natural satellite in the Solar System relative to the size of its planet, and the fifth largest satellite in the Solar System overall

backtick quotes ` allow splitting the string into multiple lines

Comment

A comment is one of the most important things in any programming language. It helps to note down important instructions for further use. There are two types of comment method single line comment which can be written as //, and the other one in a multiline comment which is written as and/* ... */

Bad Comment

Many programmers tend to write a comment in a manner that they want to make others understand what is going on with code and try to explain everything. That is not the purpose of the comment. Such type of comment considered a bad comment. In best practices, the amount of comment should be minimal, and only a necessary or critical part of the code can have some comment to make others understand the purpose of the code.

Default function parameters

A programmer can initialize a default value in a function which is called default function parameters. A default value can be anything from a number to another function.

function multiply(c, d= 5) {
return c* d;
}
console.log(multiply(10, 20));
//output: 200
console.log(multiply(20));
//output: 100

Arrow functions

Arrow functions were introduced in ES6. Arrow function allows traditional function syntax to be written in shorter syntax.


hello = function() {
return “Hello World!”;
}
console.log(hello())
hello = () => {return “Hello World!”;
}
console.log(hello())
//output: Hello World!
Hello World!

From these two examples, we can see the difference between the traditional function and the arrow function. Both have the function that gives the same output but they have some syntax difference.

These are some important topics on javascript I hope you find it useful. Thank you for reading the article.

Cross-browser testing

People use different types of devices, operating systems, and browsers to visit websites. Cross-browser testing is a testing method that allows the programmer to check is the websites works on a different type of devices, operating systems, and different browser.

Expression

An expression is a unit of code that can compute a value. Expressions always result in a single value.JavaScript has the following expression categories,

Arithmetic: evaluates to a number, for example, 12345.

String: evaluates to a character string, for example, “Hello” or “123456”.

Logical: evaluates to true or false.

Primary expressions: Basic keywords and general expressions in JavaScript.

Left-hand-side expressions: Left values are the destination of an assignment.

--

--