JavaScript
JavaScript is a popular web scripting language and is used for client-side and server-side development. The JavaScript code can be inserted into HTML pages that can be understood and executed by web browsers while also supporting object-oriented programming abilities.
Question: What is JavaScript?
Answer: JavaScript is the most popular web scripting language, used for both client-side and server-side development. Supporting object-oriented programming abilities, the JavaScript code can be inserted into HTML pages that can be understood and executed by web browsers.
Question: How is JavaScript different from Java?
Answer: Java is a programming language, whereas JavaScript is essentially a scripting language. Developers use Java for building applications that can run in a virtual machine, an operating system, or inside a browser. Contrastingly, JS code is meant to run inside a browser only.
Question: Please explain the various JavaScript data types?
Answer: There are a total of 7 basic data types supported by JavaScript. Each one of them is briefed up as follows:
- 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, it represents the undefined data type.
Question: Can you differentiate between let and Var?
Answer: Both let and var are used for variable and method declaration in JavaScript. However, the most important difference between the two JS keywords is that while the var keyword is function scoped, the let keyword is block scoped.
Question: Difference between = = and = = = ?
Answer: = is used for Assigning values to a variable in JavaScript
= = is used for comparison between two variables irrespective of the data type of variable
= = = is used for comparison between two variable but this will check script type , means it will check data type and compare two values.
Question: Could you name some built-in methods in JavaScript?
Answer: Following are some of the inbuilt methods in JavaScript:
- anchor() – Creates an HTML anchor to be used as a hypertext target
- ceil() – returns the smallest integer that is greater than or equal to the given number
- concat() – Combines two strings and returns the newer string
- constructor() – Returns the function that created the corresponding instance of the object
- Date() – Returns the present date and time
- Date.parse() – Parses a string representation of a date and time and then returns the internal millisecond representation for the same
- exec() – Searches for a match in the string parameter
- filter() – Creates a new array with all the elements of the array for which the filtering function returns true
- font color () – Displays a string in the specified color
- link() – Creates an HTML hypertext link that requests another URL
- localeCompare() – Returns a number that indicates whether a reference string comes before, after, or is the same as the given string in the sort order
- match() – Used for matching a regular expression against a string
- pop() – Removes and returns the last element from an array
- reduce() – Applies a function simultaneously for two values of the array to reduce them to a single value
- round() – Rounds off the value of the given number to the nearest integer and returns the same
- slice() – Extracts a certain section of a string and returns the remaining string
- some() – returns true if at least one element of the array satisfies the provided testing function
- toLocaleString() – Return a string value of the current number in a format that depends on the browser’s locale settings
- sup() – Displays a string as a superscript
- toSource() – Returns a string containing the source of the Boolean object
- toUpperCase() – Converts a text to uppercase
- valueOf() – Returns the primitive value of the specified object
Question: Please explain Self Invoking Function and its syntax.
Answer: Functions that are automatically invoked are termed as Self Invoking Functions. These are also known as Immediately Invoked Function Expressions and Self Executing Anonymous Functions. The general syntax of a Self Invoking Function is:
Question: What do you understand by Closures in JavaScript?
Answer: Closures provide a better, concise, creative, and expressive writing code for JavaScript developers and programmers. Technically speaking, closures are a combination of lexical environment and function.
In other words, a closure is a locally declared variable that is related to a function and stays in the memory when the related function has returned. The closure contains all local variables that were in-scope at the time of the closure creation.
The following code snippet demonstrates using a normal function in JavaScript:
function greet(message) {
console.log(message);
}
function greeter(name, age) {
return name + " says Hey!! He is " + age + " years old";
}
var message = greeter("vishal prince raaz", 24);
greet(message);
The aforementioned function can be represented in a better way by using closures. This is demonstrated in the following code snippet:
function greeter(name, age) {
var message = name + " says Hey!! He is " + age + " years old";
return function greet() {
console.log(message);
};
}
// Generate the closure
var vishalGreeter = greeter("Vishal prince raaz", 26);
// Use the closure
vishalGreeter();
Question: What are the differences between substr() and substring()?
Answer : The differences between substr and substring methods are given below:
substr()substring()It is used to return the characters in a string beginning at the specified index and returns the number of characters based on length providedIt is used to return the characters in a string beginning at the specified index and returns the number of characters based on length provided-1var x = "hello";console.log((x.substr(1, 4) == "ello"))It will print true in the log
var x = "hello";console.log((x.substring(1, 4) == "ello"))It will print false in the log
var x = "hello";console.log((x.substring(1, 5) == "ello"))//print true in console
Question: What are the differences between array and object?
Ans: The differences between array and Object are given below:
ArrayobjectThe array uses the numbered indexes to access the element in itThe object uses the named indexes to access the members in itYou should use an array when you want the element name to be numberYou should use an object when you want the element name to be a stringIt is an ordered collectionIt is a collection of unorder properties
Question: What is DOM?
Ans. Dom is a W3C (World wide web consortium) standard, when the HTML page loads in the browser, the browser creates the DOM (Document object model). It defines the HTML element as an object and allows scripts to dynamically manipulate the content, and the structure of the document.
@Hi Fi Tech Talk |
Question : What is BOM?
Answer : which provides interaction with the browser, the default object of the browser is a window. Various property provided by windows is a document, history, screen, location, navigator.
Question : What is the usefulness of the window object?
Answer :A browser’s history object could be used to switch to history pages like back and forward from the existing page or another page. 3 methods of history object are as follows:
- history.back() – This method loads the previous page.
- history.forward() – This method loads the next page.
- history.go(number) - Its number may be positive (for forward) or negative (for backward). It will load the provided page number.
These Questions are frequently asked in most IT company .
coming soon questions based on ES6 features of JavaScript which are very essential & important topic for frontend developer.
follow our face book page click here hi fi tech talk
💓Thank you 💓
8 Comments
Nice and Informative content.
ReplyDeleteThank you so much
DeleteThat's great Vishal I had learnt alot from that .
ReplyDeleteKeep it up ☺️
Thank you so much 💝 stay tuned
DeleteVery good content.
ReplyDeleteVery good big bro
ReplyDeleteVery useful and informative 👏 keep going.
ReplyDeleteVery helpful content
ReplyDelete