JavaScript ?'s Flashcards
What are the data types supported by JavaScript?
Undefined, null, boolean, string, symbol, number, object
Features of JS?
.
It is designed for creating network-centric applications.
It is an open and cross-platform scripting language.
Advantages of JS?
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.
Scopes of variables?
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.
What is the This operator?
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.
What is a Callback?
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.
What is a Closure?
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.
What is the difference between attributes and property?
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.
List out the different ways an HTML element can be accessed in a JavaScript code.
(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.
is JavaScript a dynamically typed language?
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.
What is the difference between Local storage & Session storage?
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.
What is the difference between the operators ‘==‘ & ‘===‘?
== will do type conversion while === will not, so it will just return false if not the same type
What is the difference between null & undefined?
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.
What is the difference between undeclared & undefined?
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.
What is the difference between window & document in JavaScript?
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.