DEV Community


Posted on

Every JavaScript Developer should Know this....(Part 1)

Before going to Developer path in JavaScript every future developer should acquire these concepts like Objects,Class,ES6. Below are some core concepts which we are going to learn starting from scratch.

In JavaScript, an object is an collection of key-value pairs. Each key-value pair is called a property also object is a standalone entity, with properties and type.

Image description

The key of a property can be a string and the value of a property can be JavaScript value e.g., a string, a number, an array, and even a function.

Different way to create Objects:
In JavaScript, there are four methods to use to create an object:

a. Object Literals.
b. New operator or constructor.
c. Object.create method.
d. Class

i.Object Literals:
Object Literals are more convenient way to define objects.we need to simple define the property and values inside the brackets as shown below:
Image description

ii.New operator or constructor.
The another way to create an object is to use the constructor function. Here we are calling a function using a new operator, the function will acts as a constructor and returns an new object.

Image description

iii.Object.create method
The third way where we can also create new objects using the Object.create() method

Image description

ES6 is a new standardized version of JavaScript that was released in 2015. ES6 has many new features that can help a developer to understand and write code efficiently and effectively. The class keyword to create classes in JavaScript. Now we can use the class attribute to create a class in JavaScript rather than other ways like function constructor, and we can utilize "new" operator to create an instance of that class with ease.

Image description

Here you can see we have Blog class in which we have getblogDetails() method which we will be calling on after creating instance of Blog class. This is best way to create object in JavaScript and used in many JavaScript pattern.

2.Functions in JavaScript
Functions are the most crucial part of JavaScript programming. Functions are a set of statements that are used to performs a certain task. It gives us a way to structure larger programs, to reduce repetition, to associate names with subprograms, and to isolate these subprograms from each other.

Defining a function

function definition tells about a function's name, return type, and parameters. A function definition provides the actual body of the function.

Image description

In JavaScript function is created using keyword "function" suffix with function_name. Functions have a set of parameters and a body, which includes the instruction or operations that are to be executed when the function is called inside the program.

Top comments (1)