JavaScript ?'s Flashcards

1
Q

What are the data types supported by JavaScript?

A

Undefined, null, boolean, string, symbol, number, object

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

Features of JS?

A

.
It is designed for creating network-centric applications.

It is an open and cross-platform scripting language.

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

Advantages of JS?

A

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
4
Q

Scopes of variables?

A

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
5
Q

What is the This operator?

A

points to a particular object.
In global scope, “This” refers to the global window object.
In an Object Method, “this” will point to the object that is created with the “new” keyword.
In call and apply methods, “this” refers to the object that is called in the methods.

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

What is a 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
7
Q

What is a Closure?

A

Closures are created whenever a variable that is defined outside the current scope is accessed from within some inner scope. It gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created. To use a closure, simply define a function inside another function and expose it.

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

What is the difference between attributes and property?

A

Attributes- provide more details on an element like id, type, value etc.

Property- is the value assigned to the property like type=”text”, value=’Name’ etc.

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

List out the different ways an HTML element can be accessed in a JavaScript code.

A

(i) getElementById(‘idname’): Gets an element by its ID name
(ii) getElementsByClass(‘classname’): Gets all the elements that have the given classname.
(iii) getElementsByTagName(‘tagname’): Gets all the elements that have the given tag name.
(iv) querySelector(): This function takes css style selector and returns the first selected element.

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

is JavaScript a dynamically typed language?

A

Typed Language is in which the values are associated with values and not with variables.
Dynamically: in this, the variable can hold multiple types; like in JS a variable can take number, chars.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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
12
Q

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

A

== will do type conversion while === will not, so it will just return false if not the same type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
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
14
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
15
Q

What is the difference between window & document in JavaScript?

A

JavaScript window is a global object which holds variables, functions, history, location. The document also comes under the window and can be considered as the property of the window.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
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

17
Q

What is an event bubbling in JavaScript?

A

Event bubbling is a way of event propagation in the HTML DOM API, when an event occurs in an element inside another element, and both elements have registered a handle for that event. With bubbling, the event is first captured and handled by the innermost element and then propagated to outer elements. The execution starts from that event and goes to its parent element. Then the execution passes to its parent element and so on till the body element.

18
Q

What is NaN in JavaScript

A

NaN is a short form of Not a Number. Since NaN always compares unequal to any number, including NaN, it is usually used to indicate an error condition for a function that should return a valid number. When a string or something else is being converted into a number and that cannot be done, then we get to see NaN.

19
Q

How do JavaScript primitive/object types passed in functions?

A

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.

20
Q

How can you convert the string of any base to integer in JavaScript?

A

The parseInt() function is used to convert numbers between different bases. It takes the string to be converted as its first parameter, and the second parameter is the base of the given string.

21
Q

What is the ‘Strict’ mode in JavaScript and how can it be enabled?

A

Strict mode is a way to introduce better error-checking into your code.

can’t create global variables, this undefined in global context.

22
Q

What is a prompt box in JavaScript?

A

A prompt box is a box which allows the user to enter input by providing a text box. The prompt() method displays a dialog box that prompts the visitor for input. A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops up, the user will have to click either “OK” or “Cancel” to proceed after entering an input value.

23
Q

What is the difference between Call & Apply?

A

Both invoke a function. Call uses strings as second parameter, while apply uses an array.

24
Q

diff between load event and domcontentload event

A

loaad event is only fired after dom has been loaded, domcontent loaded is fired when intial html document is intially parsed without waiting for stylesheets.

25
Q

What is same origin policy?

A

prevents JS from making requests across domain boundaries. prevents malicious scripts from obtaining sensitive data.

26
Q

What is a promise?

A

object that will produce a single value in the future. resolve = sucess, reject = failure

27
Q

immutable v mutable?

A

immutable objects’ state cannot be modified (Date, Math), mutable state can be changed.

28
Q

diff between let, const, var

A

var keyword scoped to the function they are created, or global and can be hoisted. Let and const will not allow hoisting, block scoped (only accessible to nearest set of curly braces.)

29
Q

arrow functions?

A

this within arrow functions is bound to the enclosing scope, usueful in invoking callbacks (in react)

30
Q

what is an higher order function?

A

that takes one or more functions as argument. map method common. (repeated operations)