0% found this document useful (0 votes)
1K views

javascript_interview_questions

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

javascript_interview_questions

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

1)what is javascript ? what is the role of javascript engine?

HTML
CSS
JAVASCRIPT:
javascript is a programming languae that is used for converting static web page
into interactive and dynamica webpages

v8
spidermonke
javascript core
chakra

2)what are the client side and server side?


client side applications runs in browser
servers high level server machines

a client is a device, application or sofware component that requests and consumes


servies or resources from a server
a server is a device, computer or sofware application that provides serives,
resources or functions to clients.

3) what are the variables ? what is differnce betwee var, let and const keyword?
variables are used to store data

var count = 10 //scopt function


funciton example(){
if(true){
var count = 10;
console.out(count);
//output:10
}
console.log(count);
//ouptut:10

let creates a block scoped variable


let => scope block level
function example(){
if(true){
let count = 10;
console.log(count);
//ouput:10
}

console.log(count);
//ouptut:uncaught
//reference:error
//count is not defined

const can be assigned only once, and its value cannot be changed afterwards
const = > block level
//using const
const z = 10;
z = 20;
console.log(z);

this will result an error

4) what are data types in javascript?


A Data types determines the type of variable
//string
let messag = 'HEllO';

//Boolena
let istrue=true;

//Undefined
let x;
console.log(x);
//Output undefined

//Null
let y=null;
console.log(y);
=======================================================================
Types of Data Types:
============================
Primitive:
Numbers
Strings
Booleans
Undefined
Null

Nonprimitive:
================
Objects
Array
Function
Date
RegExp

5)What are the operators and what are the types of operators in JS ?
operators are used to perform operations on operands

Types of Operators
Arithmetic Operators
let x=12; y=14;
console.log(x+y)
console.log(x-y)
console.log(x*y)
console.log(x/y)
console.log(x%y)
console.log(x*y)

Assignment Operators
let x=10;
x+=5;
x=x+5;
console.log(x);

Comparison operators
let x=5;
let y=3;
console.log(x>y);
console.log(x<y);
console.log(x>=y);
console.log(x<=y);
console.log(x==y);
console.log(x!==y);

Logical Operators
let x=true;
let y=false;
console.log(x&&y);
//Logical AND: False

console.log(x||y);
Logical OR: true

console.log(!x);
String Operators

String Operators:
=================
let a = 'Hello';
let b = ' world';

var c=(a+b);
//Concatenation;
//Output: Hello world;

5) Waht are the conditional statments in JS?


1) IF else
let x=5;
if(x>10){
console.log("1");
}
else if(x<5){
console.log("2");
}
else{
console.log("3");
}
//Output

2)Ternary operator
let y = 20;
let z = y > 10 ? "1" : "0"
console.log(z);
//Output 1;

3)Switch Statement

let a=5;
switch(a){
case 1:
console.log("1");
break;

case 5;
console.log("2");
break;
default:
console.log("3");
}
//output 2:

6)What are the selector in JAVASCRIPT?


DOM Selector Methods
selector in js help to get specific elements from DOM based on IDs, ClassNames,
tagnames
getElementById()
getElemetnsByClassName()
getElementsByTagname()
querySelector()
querySelectorAll()

7)what is the differnce bteween getElementById, getElmenetByClassNamea and


getElementsByTagName?
<!DOCTYPE html>
<html>
<head>
<title>DOM Methods</title?>
</head>
<body>
<div id="myDiv" class="myClass">1</div>
<div class="myClass">2</div>
<div class="myClass">3</div>

//Get elementByID
It is used to select a single element by id
const elementByID = document.getElementById("myDiv");
console.log(elelmentByID.innerHTML);

//multiple element that share the same class


const elements = document.getElementByClassName('myClass');
for(let i=0; i<elements.length; i++){
console.log(elements[i].textcontent);
}
//ouputt 2;

//getElementByTagName = select multiple elements by TagName;


const elementTag = document.getElementsByTagname("div");
for(let i=0; i<elementTag.legth; i++){
console.log(element[i].textcontent);
zzcx}

8) what is DOM? what is the differnce betweem HTML and the DOM ?
DOM Stands for Document Object Model represent the webpage as a tree like structure
that allows javascriptto dynamically access and manipulate the content and
structure of the webpage

DOM is a tree kiind of structure in the form Hirarcy in the browser memory

if we want to add, delete orupdate and html element via js the user wants to add
one more paragraph inside the body elelment with the help of js one more element
has created and can be converted into html
9)what is a loop and types of loop in js?
a loop is a programming way to run a piece of code repeatedly until a certain
condition is met
javascript loops
for
wwhile
do-while
for...of
for...in

10)what are functions in JS? what are the types of functions in JS?
A fuction is a reusable block of code that performs a specific task;

funciton sum(a,b){ - name


let c= a+b; ----> body
return c;
}
result=sum(5,10);--> call

Types of Funcitons:
Named Functions;
Anonymous Functions;
Functions Expression;
Arrow Functions
IIFE
Callback Fucntions
HighOrder Functions

11) What are arrow functions in JS? what is it use?

You might also like