Javascript common interview question!

I think this tutorial might help you!

  1. Truthy and Falsy values

In javascript, when you write an if/else condition, you can check which value is true and which value is false.

code example

by this example, we can understand that all positive value is true.

but negative value?

by this example, you could understand that all positive and negative value is true. even object{} array[] & grater than 0 is truthy value . but if the number is -0 & "", null then it's false.

2.Null Vs Undefined

The undefined property indicates that a variable has not been assigned a value, or not declared at all.

many ways we get find undefined, like

why you get undefined? CZ you cant return the value/function!

in this case, the num2 parameter is not defined that's why!

and this case you get undefined because there is no value re under info

The value null represents the intentional absence of any object value.

3.double equal (==) vs triple equal (===)

this is a very popular interview question!

if double equal(==) find its value as equal that has user-define.

that's ok no problem because it not check the type of the values. like

But if you use triple equal (===)instead of double equal( ==) in example code you got a false result

but why you got your result is false?

because in this condition its searches for a value that is all equal (type& value).

but in this code, it finds the value as an equal but the type is not the same/equal.

remind that: triple equal (===) check both value and type.

like this below example

4.window, global variable, global scope

what is window?

The Window Object It represents the browser’s window. All global JavaScript objects, functions, and variables automatically become members of the window object. Global variables are properties of the window object. Global functions are methods of the window object.

global variable

A JavaScript global variable is declared outside the function or declared with window object. It can be accessed from any function.

Let’s see the simple example of a global variable in JavaScript.

5. Find the largest element of an array

it is also the most important interview question.

if you want to find out the largest/maximum value from the array, this code example is for you…

I think you could understand.

6. Remove duplicate item from an array

If you were want to remove duplicate numbers or names from an array. This code might also help you.

7.Count the number of words in a string

If you were want to Count the number of words in a string from an array. This code might also help you.

8.Reverse a string

If you were want to Reverse a string. This code might also help you, I show you step by step for your understanding...

first of all, you split() the string

then reverse the string using reverse()

now join all the text to reverse the string using join()

I think you could understand.

9.Calculate Factorial of a number using for loop

do you know what is Factorial?

The factorial, symbolized by an exclamation mark (!), is a quantity defined for all integer s greater than or equal to 0.

For an integer n greater than or equal to 1, the factorial is the product of all integers less than or equal to n but greater than or equal to 1. The factorial value of 0 is defined as equal to 1. The factorial values for negative integers are not defined.

let’s get a code example

10.Check whether a number is a Prime Number or not!

what is Prime Number?

A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 13is prime.

Now you can find out any prime number by using this code example!

MERN Stack web developer