JS interview questions Flashcards
What is JavaScript(JS)?
- lightweight
- interpreted programming language
- object-oriented capabilities
- allows you to build interactivity into otherwise static HTML pages.
What are the features of JavaScript?
- JavaScript is a lightweight, interpreted programming language.
- JavaScript is designed for creating network-centric applications.
- JavaScript is complementary to and integrated with Java.
- JavaScript is complementary to and integrated with HTML.
- JavaScript is open and cross-platform.
What are the advantages of JavaScript?
- Less server interaction? You can validate user input before sending the page off to the 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
Why is javascript called Richer Interface?
You can use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors.
Is javascript case-sensitive?
Yes, JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.
How can we create an object in JS?
var object = { name: "obj", age: 10 };
How can we read the properties of an object in js?
Can write and read properties of an object using the dot(.) notation or array type notation
Can you define arrays using the array literal as follows? var x = []; var y = [1, 2, 3, 4, 5];
yes
An array has a length property that is useful for iteration. Can we read elements of an array as follows? for (var i = 0; i < x.length; i++)
no. the code is incomplete. for (var i = 0; i < x.length; i++) { var ele = x[i]; } now we can read elements of an array x
How many types of functions does JS support?
A function in JavaScript can be either named or anonymous.
How to define an anonymous function?
An anonymous function can be defined in a similar way as a normal function but it would not have any name.
give an example of a built-in method that calls a function for each element in the array?
forEach, map … methods calls a function for each element in the array.
Which type of variable among global and local, takes precedence over others if names are same?
A local variable takes precedence over a global variable with the same name.
Difference between “var” and “let” Keywords?
Var was there from the beginning but the let was introduced in ES2015/ES6.
Let has block scope and “Var” has function scope
Difference between “==” and “===” ?
” ==” only compares values “===” compare values and type both.
Difference between “undefine” and “NULL” Keywords?
null value means does not exist. not defined is when something such as a variable is not defined in the system but is being accessed