DEV Community

Sonu Jha
Sonu Jha

Posted on

Javascript Interview Questions - Entry Level

Everyday i will be sharing few Javascript Interview Questions to help you understand the languauge even better.

So lets get started with basic questions that are asked in the interview.

1> what is typeOf operator ?
Ans. typeOf operator examines the value and tells you what type the value is.

Ex: var a =14;
typeof(a); //returns Number.

2> What is object type ?

Ans. An object type is nothing but a collection of properties with name and value pair.

Ex: var obj = {
a : "Hello",
b : 45
}
obj.a //"Hello" accessed with doted notation
obj.b //45

obj["a"] //"Hello "accessed with bracket notation
obj["b"] //45

Bracket notation is also helpful if you want to access a property/key but the name is stored in an another variable, such as:

obj b= "a"

obj[b] //"Hello"
obj["b"] //45

3> Explain array in javascript.

Ans. An array is an object that holds value(of any type) not particularly in named properties/key, but rather in numerically indexed positions.

var arr = ["hello", 1 , true]
arr[0] // "hello
arr[1] // 1
arr[2] // true

typeof(arr) // "object"

4> what is scope in javascript ?

Ans. Each Function gets its own scope. So Scope is basically a collection of variables as well as the rules for how those variables are accessed by names.
only code inside that function can access the function's scoped variable.

5> Explain equality in javascript.
Ans. Javascript have both strict and type-converting comparions:

strict comparison (eg === checks for value equality without coercion)
Abstract comparison (eg == checks for value with coercion allowed)

Ex:
var a = "42"
var b = 42

a === b // false
a == b // true

6> what is let keyword in javascript ?

Ans. Es6 lets you declare variable within the individual blocks (pairs of {...}) using the let keyword.

let will not let you declare same variable within the same scope whereas var will simply replace it.

Self Study : Try to understand temporal dead zone, Hoisting

7> Explain null and undefined.

Ans. null means that it is Currently unavilable.
undefined means it hasnt been initialized.

8> What is Strict Mode ?

Ans. Strict Mode is a new Feature in ECS5 that allows you to place a program or a function in a "Strict" operating context. Strict context prevents from certain action to be taken and throws more exceptions.

Ex. function(){
"use Strict"
}

9> what is a polyfill ?

Ans. Polyfil is a piece of code or a plugin that allows the functionality that works on modern browser to also work on older browsers.

10> Explain event bubbling and how one may prevent it.

Ans. Event Bubbling is the concept in which an event triggers at the deepest possible element and trigers on parent elements in nesting order.

one way to handle event bubbling is event.stopPropgation()

11> what does "use strict" do ?

Ans "use strict" is written at a top of a function or a program that helps you write a safer code and throws error if a global variable is created by mistake.

Top comments (0)