Core Concepts of JS every developer should know

Riyan Hasan
4 min readMay 8, 2021

Today I am going to discuss some core concepts of JS. This is also very important for interviews.

Truth & Falsy Value

In java, language values are not limited to true or false only or limited to boolean data types.

When you write an if/else statement in any other language, you expect to pass a value in the if() condition that is strictly boolean which means either true or false. A falsy value is something that evaluates to FALSE, for instance when checking a variable. There are 6 falsy values false, undefined, null, “ “, NaN, 0. Except for this, all values are truthy values. a truthy value is a value that is considered true when encountered in a Boolean context. All values are truthy unless they are defined as falsy

Example

2.Difference between “==” and “===”

In JS equal to an operator is a very important operator, many important operations and conditions can be checked by using this operator. When double equal is checked it can not provide an exact result it such as if we can declare

In this, the above example operation will be performed, the number and string are not equal but still, double equal cannot differentiate it.

But here output will not be equal, as it can differentiate it. Triple equal is used to compare passwords, important data to get perfect output.

3.How recursion works

Generally, recursive functions are used to break down a big problem into smaller ones. You can find that they are heavily used in the data structures like binary trees and graphs and algorithms such as binary search and quicksort. Basically, A recursive function is a function that calls itself until it doesn’t. and this technique is called recursion.

4.Write basic concept of Fibonacci series using recursive and iterative function

Recursive Function

function fibonacci(number) {

if(number <= 1){

return 1;

}else {

return fibonacci(number — 1) + fibonacci(number — 2);

}

}

Iterative way

function fibonacci(value){

let a = 1;

let b = 0;

let temp;

while (value >= 0){

temp = a;

a = a + b;

b = temp;

number — ;

}

return b;

}

5.What is an event bubble?

The event bubbling process starts with the element that triggered the event and then bubbles up to the containing elements in the hierarchy. It is basically a term to use in the nested features, to understand which should occur first.

Example

A button is clicked and the event is directed to the button Then if an event handler is set for that object, the event is triggered. Finally, if no event handler is set for that object, the event bubbles up to the object’s parent

6.Encapsulation

JavaScript is a sturdy object-oriented scripting language, it is capable of building complex applications on both the client and the server. It is however one of the main concepts in OOP. It is a process of binding the data with the functions which act upon the data. Encapsulation allows us to control and validate the data. In JavaScript, variables resemble data. This will help restrict the unauthorized use of the variables.

7. 5 is a prime number or not? How do you calculate this !

5 is a prime number.

const number = 5;

let isPrime = true;

if (number === 1) {

console.log(“1 is neither prime nor composite number.”);

}

else if (number > 1) {

for (let i = 2; i < number; i++) {

if (number % i == 0) {

isPrime = false;

break;

}

}

if (isPrime) {

console.log(`${number} is a prime number`);

} else {

console.log(`${number} is a not prime number`);

}

}

8.What is JS? Key features of JS?

JavaScript- is an object-oriented programming language. It is commonly used to create interactive websites. It was originally developed by Netscape as a means to add dynamic and interactive elements to websites.

Key features of JS

  • Object-Centered Script Language
  • Client edge Technology
  • Else and If Statement
  • Interpreter Centered
  • Easy Syntax
  • Case Sensitive format
  • Light Weight and delicate
  • Statements Looping
  • Handling Events

What is DOM?

DOM is Document Object Model. When an HTML document is loaded in the browser, it becomes a document object. It is the root element that represents the HTML document. It has properties and methods. With the help of document objects, we can add dynamic content to our web page.

--

--