0% found this document useful (0 votes)
6 views6 pages

JavaScript Interview Q&A for Beginners

The document contains 30 beginner-level interview questions and answers about JavaScript, covering fundamental concepts such as variables, data types, loops, and operators. It highlights key differences between JavaScript and Java, as well as between various JavaScript features like var, let, and const. Each question is accompanied by examples to illustrate the concepts effectively.

Uploaded by

sravani2917
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

JavaScript Interview Q&A for Beginners

The document contains 30 beginner-level interview questions and answers about JavaScript, covering fundamental concepts such as variables, data types, loops, and operators. It highlights key differences between JavaScript and Java, as well as between various JavaScript features like var, let, and const. Each question is accompanied by examples to illustrate the concepts effectively.

Uploaded by

sravani2917
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript Beginner Interview Questions &

Answers (30 Qs)

1. What is JavaScript?
JavaScript is a lightweight, interpreted programming language mainly used for adding interactivity
to web pages. It runs in the browser and on servers ([Link]).

Example:
[Link]('Hello, JavaScript!');

2. Difference between JavaScript and Java?


Java is compiled, strongly typed, runs on JVM.
JavaScript is interpreted, loosely typed, runs on browsers.

Example:
let language='JavaScript';
[Link]('This is not Java, it’s '+language);

3. What are variables in JavaScript?


Variables store data values. Declared using var, let, or const.

Example:
let name='Rahul';
[Link](name);

4. Difference between var, let, and const?


var: Function-scoped, can be redeclared.
let: Block-scoped, cannot be redeclared.
const: Block-scoped, value cannot change.

Example:
var a=10;
let b=20;
const c=30;
[Link](a,b,c);

5. What are data types in JavaScript?


Two categories:
- Primitive: string, number, boolean, null, undefined, symbol, bigint.
- Non-primitive: objects, arrays, functions.
Example:
let str='Hello'; let num=10; let flag=true;
[Link](typeof str, typeof num, typeof flag);

6. What is type coercion?


Automatic conversion of one data type to another.

Example:
[Link]('5' + 2); // '52'
[Link]('5' - 2); // 3

7. What are operators in JavaScript?


Arithmetic (+,-,*,/,%); Assignment (=,+=,-=); Comparison (==,===,!=,!==,>,<); Logical (&&,||,!).

Example:
let x=10, y=5;
[Link](x+y);
[Link](x>y);
[Link](x==='10');

8. Difference between == and === ?


== checks value only (loose equality). === checks value and type (strict equality).

Example:
[Link](5 == '5'); // true
[Link](5 === '5'); // false

9. What is a string in JavaScript?


A string is a sequence of characters enclosed in quotes.

Example:
let str='Hello World';
[Link]([Link]);

10. How to concatenate strings?


Using + or template literals.

Example:
let first='Hello', second='JS';
[Link](first+' '+second);
[Link](`${first} ${second}`);

11. How to find a character in a string?


Using charAt() or index.

Example:
let str='JavaScript';
[Link]([Link](4));
[Link](str[4]);

12. What are loops in JavaScript?


Loops repeat a block of code. Common loops: for, while, do…while.

Example:
for(let i=1;i<=3;i++){[Link]('Loop count:',i);}

13. Difference between for and while loop?


for: Used when number of iterations is known.
while: Used when iterations depend on a condition.

Example:
let i=1; while(i<=3){[Link]('While Loop:',i);i++;}

14. What is the if statement?


It executes code only if a condition is true.

Example:
let age=18; if(age>=18){[Link]('Eligible to vote');}

15. What is if-else statement?


It provides two paths: if condition true → one block, else → another.

Example:
let age=16; if(age>=18){[Link]('Adult');}else{[Link]('Minor');}

16. What is else if ladder?


Used when multiple conditions are checked.

Example:
let marks=75; if(marks>=90) [Link]('Grade A'); else if(marks>=60)
[Link]('Grade B'); else [Link]('Grade C');

17. What is the difference between null and undefined?


null: Intentional empty value.
undefined: Variable declared but not assigned.

Example:
let a; let b=null; [Link](a,b);

18. What is NaN in JavaScript?


NaN = Not a Number. Returned when math operation fails.

Example:
[Link](0/0);
[Link]('hello'*3);

19. What is typeof operator?


It returns the type of a variable.

Example:
let x=100; [Link](typeof x);

20. What is a template literal?


String enclosed in backticks that allows embedding variables.

Example:
let name='Nani'; [Link](`Hello, ${name}!`);

21. What is increment and decrement operator?


++ increases by 1, -- decreases by 1.

Example:
let n=5; [Link](++n); [Link](n--);

22. What is the modulus operator (%) ?


It gives remainder after division.

Example:
[Link](10%3);
23. Difference between break and continue?
break: exits loop. continue: skips current iteration.

Example:
for(let i=1;i<=5;i++){ if(i==3) continue; [Link](i);}

24. What is a boolean?


It represents true or false.

Example:
let isActive=true; [Link](typeof isActive);

25. What is string interpolation?


Inserting variables inside strings using template literals.

Example:
let a=10,b=20; [Link](`Sum=${a+b}`);

26. What is nested if?


If statement inside another if.

Example:
let age=20, hasID=true; if(age>=18){ if(hasID){ [Link]('Allowed');}}

27. Difference between while and do-while loop?


while: condition checked first.
do-while: executes once before checking condition.

Example:
let i=5; do{[Link]('Do while:',i);i++;}while(i<5);

28. What is a truthy and falsy value?


Truthy: values considered true (1,'hi',[]).
Falsy: values considered false (0,'',null,undefined,NaN).

Example:
if('hello') [Link]('Truthy'); if(0) [Link]('Falsy');

29. Difference between primitive and reference data types?


Primitive: Stored by value (number,string).
Reference: Stored by reference (object,array).

Example:
let arr=[1,2,3]; let copy=arr; [Link](4); [Link](arr);

30. Program to check if a number is even or odd?

Example:
let num=7; if(num%2===0){[Link]('Even');}else{[Link]('Odd');}

You might also like