Quick Revision of Important Topics in JavaScript.(Part-1)

Let’s start with “What is JavaScript? What makes it Unique from Others?”

It was created by Brendan Eich in 1995 during his time in Netscape (Initially named Mocha). It was conceived as both Client and Server-side Scripting Language. The first version came with Internet Explorer 3.0 in 1996. Quickly, got to be known for its Object Model and Functional feature.

With NodeJS and V8 and other scripts as bought JavaScript to places it never thought for.

Things to know about JavaScript, before starting?

It is any Object-oriented Programming language commonly used for creating interactive effects with web browsers.

In other words, Object-Oriented Programming (OOP) program is composed of objects (Key-value pairs), which communicate with each other, which may be arranged into hierarchies, and which can be combined to form additional Objects

And which help Developer to Create interactive website with quick response and Dynamic data correction. It is embedded into all Browsers with the different engines running behind, like V8 in Chrome, Spider-Monkey in Mozilla, etc.

JavaScript

A major difference between Java and JavaScript?

Java is a complete programming language and JavaScript is a coded program that can be introduced to HTML pages.

Java is also an Object-Oriented Programming Language like C++ and C, where JavaScript is a Client-side Scripting language.

Data-types supported by JavaScript?

Any programming language would be more efficient with its support to its Data-types

In JavaScript, there are two Kinds of Data,

1.Primitive type.

2.Objects

Primitive type- Are the one which is immutable(once a value is assigned to such data type, the value cannot be changed and if the value is changed this will result in new memory allocation ).

The Primitive types are:

1. Undefined

2. Null

3. Boolean

4. String

5. Symbol

6. Number

Object Data type- The values in these can be changed but this would not result in a complete change of memory allocation. Arrays and Objects being the example. (Everything is an Object in JavaScript)

Important Feature of JavaScript?

As JavaScript is a Scripting Language, its highlighting features are:

1. It’s a lightweight, interpreted programming language. (Making it easy for Clint side hosting).

2. It is designed for creating network applications. (Can be used to detect a user’s OS.)

3. It is complementary to and integrated with Java.

4. It is also complementary to HTML.

5. It is an object-based language as it uses predefined objects.

1. Doesn’t Support Multi-threading.

2. And no Multi-Processor capabilities.

“Is JavaScript a case Sensitive Language?”

Yes, it is Case-Sensitive language. Most followed case type being- CammelCase, Snake_case.

What are the advantages of JavaScript?

1.Less Server Interaction-We can always validate the user input before sending the page to the server, which saves server traffic which means less load in the server.

2. Quick Feedback to users/Visitors- So they don’t have to wait for a page reload to see if they forgot to enter something.

3.Increased Interactivity- Can create an interface for the user to make them more attractive and Unique.

4.Richer Interfaces- So users can add Drag and components and Slider for more comfort to users.

How to Create an Object in JavaScript?

Objects are a mix of Key, Value pairs that can be defined according to developer comfort and called for primitive and non-primitive data-types. Which can even handle function within them. Also carrying properties like inheritance, mutability, and Encapsulation (Which will be explained further with better examples.)

Ways to Create Objects are:

1.Object Constructor: The simplest way to create empty object is using the Object Constructor.

var obj = new Object();

2.Object Create Method: New object by passing the prototype object as a parameter

var obj = Object.create(null);

3.Object literal syntax: This is equivalent to create method when it passes null as parameter.

var obj = {};

4.Function constructor : Similar to Construction

function Person(name){
var obj = {};
obj.name=name;
obj.age=25;
return obj;
}
var obj = new Person("Kota");

5.Function constructor with prototype: (Will learn about Prototype further )

function Person(){}
Person.prototype.name = "Kota";
var obj = new Person();

6. ES6 Class syntax: class feature to create

class Person {
constructor(name) {
this.name = name;
}
}
var obj = new Person("Kota");

7.Singleton Pattern:can be only instantiated once

var object = new function(){
this.name = "Kota";
}

How can you create an Array in JavaScript?

  1. Using Assignment Operator:
var array = [];
var array2 = [1,2,3,4,5];

2.Using new operator: Create an array with length set to number.

var arr = new Array(2);// 2 is the length of array
arr; [empty x 2]
arr.length; //2
arr[0]; undefined

3.Using Array.from:

var arr = Array.from({length : 2});
arr; // [undefined, undefined]arr[0] = 1;
arr[1] = 2;
var arrCopy = Array.from(arr);
arrCopy; // [1,2]

4.Using Spread operator:

var arr =  [1,2,3,4,5];
var array2 = [ ...arr ];
array2; // [1,2,3,4,5]

5.Using Array: Create array with argument as items

var array = Array(1,2,3,4,5);
array; // [1,2,3,4,5]

6.Using Array.of

var array = Array.of(5);
array; / [5]
var array2 = Array.of(1,2,3,4,5,6, "string");
array2; // [1, 2, 3, 4, 5, 6, "string"]

What is a name function in JavaScript and how to define it?

The function is a fundamental block of code that can return after executing that code and also can take input from variables.

var x = myFunction(4, 3);
// Function is called, return value will //end up in x
function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}
function myFunction(p1, p2) {
return p1 * p2;
// The function returns the product of p1 and p2
}

What are argument objects in JavaScript and how to get the type of the argument passed to a function?

function call(x){
console.log(typeof x)
} //
call()// --> "undefined"
call("x") //-->"string"
call(1)//-->"number"

Arguments are local variables passed to a function, we can refer to that argument inside that function using “arguments” as an object, type of is inbuilt to get the type of that input.

What is the scope of a variable in JavaScript?

Scope of a variable is the region of that variable in which it is defined. In JavaScript, there are two scopes.

Global Variable- It is visible everywhere in your JavaScript code.

Local Variable- It will be visible only within a function where it is defined.

Mostly we used “let” to define such variables.

As this could be a long Blog to read, I have divided it into parts, if interested to continue can check them on my medium profile page.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why did SitePen start TSConf?

How to REST API: a tale of Node.js, Express and Typescript

Dynamically Convert Plain Objects Into TypeScript Classes

https://youtu.be/dEZOGTo93Mw

Reason in a Nutshell — Getting Started Guide

Use Constructor in React Functional Component with Custom Hooks

Increase Node.js Performance with Libuv Thread Pool

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
kota krishna reddy

kota krishna reddy

More from Medium

CoreDump: A Guessing Game.

Understanding Functional Component and Class Component

CHAPTER 01 -BREAKING THE SURFACE

International Date Line! Experience the Time-Travel (not really)