Interview Questions Flashcards

1
Q

Including JavaScript in an HTML Page

A

//JS code goes here

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe the difference between var, let and const

A

var
The most common variable. var keyword is function scoped. Can be reassigned but only accessed within a function. Variables
defined with var move to the top when code is executed.

const
Cannot be reassigned and not accessible before they appear within the code.

let
Similar to const, however, let variable can be reassigned but not re-declared. let keyword is block scoped.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is JavaScript?

A

JavaScript is a lightweight, interpreted programming language with object-oriented capabilities that allows you to build interactivity into otherwise static HTML pages. The general-purpose core of the language has been embedded in Netscape, Internet Explorer, and other web browsers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the data types supported by JavaScript?

A

The data types supported by JavaScript are:

Boolean – Represents true and false values
Null – Represents empty, nothing, and unknown type of values
Number – Represents both integer and floating-point values
Object – Used for storing collections of data or more complex entities
String – Represents single-character, multi-character, and alphanumeric values
Symbol – Used for creating unique identifiers for objects
Undefined – Represents value not assigned. If a variable is only declared and not assigned in JS, then it represents the undefined data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the advantages of JavaScript?

A

Following are the advantages of using JavaScript −

Less server interaction − You can validate user input before sending the page off to the server. This saves server traffic, which means less load on your server.

Immediate feedback to the visitors − They don’t have to wait for a page reload to see if they have forgotten to enter something.

Increased interactivity − You can create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.

Richer interfaces − You can use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the scopes of a variable in JavaScript?
The scope of a variable is the region of your program in which it is defined. JavaScript variable will have only two scopes.
• Global Variables − A global variable has global scope which means it is visible everywhere in your JavaScript code.
• Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.

A

The scope of a variable is the region of your program in which it is defined. JavaScript variable will have only two scopes.

  • Global Variables − A global variable has global scope which means it is visible everywhere in your JavaScript code.
  • Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the purpose of ‘This’ operator in JavaScript?

A

The JavaScript ‘this’ keyword refers to the object it belongs to. This has different values depending on where it is used. In a method, this refers to the owner object and in a function, this refers to the global object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Callback?

A

A callback is a plain JavaScript function passed to some method as an argument or option. It is a function that is to be executed after another function has finished executing, hence the name ‘call back‘. In JavaScript, functions are objects. Because of this, functions can take functions as arguments, and can be returned by other functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does TypeOf Operator work?

A

The typeof operator is used to get the data type of its operand. The operand can be either a literal or a data structure such as a variable, a function, or an object. It is a unary operator that is placed before its single operand, which can be of any type. Its value is a string indicating the data type of the operand.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between Local storage & Session storage?

A

Local Storage – The data is not sent back to the server for every HTTP request (HTML, images, JavaScript, CSS, etc) – reducing the amount of traffic between client and server. It will stay until it is manually cleared through settings or program.

Session Storage – It is similar to local storage; the only difference is while data stored in local storage has no expiration time, data stored in session storage gets cleared when the page session ends. Session Storage will leave when the browser is closed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between the operators ‘==‘ & ‘===‘?

A

The main difference between “==” and “===” operator is that formerly compares variable by making type correction e.g. if you compare a number with a string with numeric literal, == allows that, but === doesn’t allow that, because it not only checks the value but also type of two variable, if two variables are not of the same type “===” return false, while “==” return true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference between null & undefined?

A

Undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value. Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between undeclared & undefined?

A

Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered. Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between innerHTML & innerText?

A

innerHTML – It will process an HTML tag if found in a string

innerText – It will not process an HTML tag if found in a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do JavaScript primitive/object types passed in functions?

A

One of the differences between the two is that Primitive Data Types are passed By Value and Objects are passed By Reference.

By Value means creating a COPY of the original. Picture it like twins: they are born exactly the same, but the first twin doesn’t lose a leg when the second twin loses his in the war.

By Reference means creating an ALIAS to the original. When your Mom calls you “Pumpkin Pie” although your name is Margaret, this doesn’t suddenly give birth to a clone of yourself: you are still one, but you can be called by these two very different names.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly