Skip to main content

JavaScript

JavaScript (JS) is the most popular lightweight scripting and interpreted programming language. It was developed by Brendan Eich in 1995. It is well-known as a scripting language for web pages, mobile apps, web servers, and many more. It is an important language for aspiring front-end and back-end developers. some job roles demand individuals to be fluent in JavaScript.

Javascript is one of the most popular programming languages in the world currently, and it is basically the language of the web. It is a lightweight, cross-platform, and interpreted programming language, primarily used for web development and backend development. Javascript is a language that is used widely on both the client and server sides of development. Javascript offers a vast standard library that has a wide variety of functions and methods available to help in the process of development, making the entire process easier and hassle-free.

Javascript can be added to our HTML code in mostly 2 ways:

Internal Javascript: Javascript in this case is directly added to the HTML code by adding the JS code inside the <script> tag, which can be placed either inside the <head> or the <body> tags based on the requirement of the user.
External Javascript: In this case, the Javascript code is written inside an external file with the extension file_name.js, and then the file is linked to the HTML file inside the <head> tag.


Features of Javascript
Javascript is a lightweight, cross-platform, and interpreted language.
It was developed with the main intention of DOM manipulation, bringing forth the era of dynamic websites.
Javascript functions are objects and can be passed in other functions as parameters.
Can handle date and time manipulation.
Can perform Form Validation.
A compiler is not needed.


JavaScript Interview Questions
Let’s discuss some common questions that you should prepare for the interviews. These questions will be helpful in clearing the interviews specially for the frontend development role.

1. What are the differences between Java and JavaScript? 
JavaScript is a client-side scripting language and Java is object Oriented Programming language. Both of them are totally different from each other.

JavaScript: It is a light-weighted programming language (“scripting language”) for developing interactive web pages. It can insert dynamic text into the HTML elements. JavaScript is also known as the browser’s language.
Java: Java is one of the most popular programming languages. It is an object-oriented programming language and has a virtual machine platform that allows you to create compiled programs that run on nearly every platform. Java promised, “Write Once, Run Anywhere”.

2. What are JavaScript Data Types? 
There are three major Data types in JavaScript.

Primitive
  • Numbers
  • Strings
  • Boolean
  • Symbol
Trivial
  • Undefined
  • Null
Composite
  • Objects
  • Functions
  • Arrays
3. Which symbol is used for comments in JavaScript? 
Comments prevent the execution of statements. Comments are ignored while the compiler executes the code. There are two type of symbols to represent comments in JavaScript:

Double slash: It is known as a single-line comment.
// Single line comment
Slash with Asterisk: It is known as a multi-line comment.
/* 
Multi-line comments
...
*/

4. What would be the result of 3+2+”7″?
 Here, 3 and 2 behave like an integer, and “7” behaves like a string. So 3 plus 2 will be 5. Then the output will be 5+”7″ = 57.

5. What is the use of the isNaN function?
 The number isNan function determines whether the passed value is NaN (Not a number) and is of the type “Number”. In JavaScript, the value NaN is considered a type of number. It returns true if the argument is not a number, else it returns false.

6. Which is faster in JavaScript and ASP script?
 JavaScript is faster compared to ASP Script. JavaScript is a client-side scripting language and does not depend on the server to execute. The ASP script is a server-side scripting language always dependable on the server.

7. What is negative infinity?
 The negative infinity is a constant value represents the lowest available value. It means that no other number is lesser than this value. It can be generate using a self-made function or by an arithmetic operation. JavaScript shows the NEGATIVE_INFINITY value as -Infinity.

8. Is it possible to break JavaScript Code into several lines?
 Yes, it is possible to break the JavaScript code into several lines in a string statement. It can be broken by using the backslash n ‘\n’. 
For example:

console.log("A Online Computer Science Portal\n for Interview goal")

let gfg= 10, GFG = 5,
abc =
gfg + GFG;

The code-breaking line is avoid by JavaScript which is not preferable.

9. Which company developed JavaScript?

Netscape developed JavaScript and was created by Brenden Eich in the year of 1995.

10. What are undeclared and undefined variables?

  • Undefined: It occurs when a variable is declare but not assign any value. Undefined is not a keyword.
  • Undeclared: It occurs when we try to access any variable which is not initialize or declare earlier using the var or const keyword. If we use ‘typeof’ operator to get the value of an undeclare variable, we will face the runtime error with the return value as “undefined”. The scope of the undeclare variables is always global.

11. Write a JavaScript code for adding new elements dynamically. 

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
</head>

<body>
    <button onclick="create()">
        Click Here!
    </button>

    <script>
        function create() {
            let abc = document.createElement('abc');
geeks.textContent = "InterviewGoal"; geeks.setAttribute('class', 'note'); document.body.appendChild(abc);
} </script> </body> </html>

13. What do you mean by NULL in JavaScript?
 The NULL value represents that no value or no object. It is known as empty value/object.

14. How to delete property-specific values?
 The delete keyword deletes the whole property and all the values at once like

let gfg={Course: "DSA", Duration:30};
delete gfg.Course;
15. What is a prompt box?
 The prompt box is a dialog box with an optional message prompting the user to input some text. It is often used if the user wants to input a value before entering a page. It returns a string containing the text entered by the user, or null.

16. What is the ‘this’ keyword in JavaScript?
 Functions in JavaScript are essential objects. Like objects, it can be assign to variables, pass to other functions, and return from functions. And much like objects, they have their own properties. ‘this’ stores the current execution context of the JavaScript program. Thus, when it use inside a function, the value of ‘this’ will change depending on how the function is defined, how it is invoked, and the default execution context.

17. Explain the working of timers in JavaScript. Also elucidate the drawbacks of using the timer, if any.
The timer executes some specific code at a specific time or any small amount of code in repetition to do that you need to use the functions setTimout, setInterval, and clearInterval. If the JavaScript code sets the timer to 2 minutes and when the times are up then the page displays an alert message “times up”. The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.

18. What is the difference between ViewState and SessionState?
ViewState: It is specific to a single page in a session.
SessionState: It is user specific that can access all the data on the web pages.

19. How to submit a form using JavaScript?
You can use document.form[0].submit() method to submit the form in JavaScript.

20. Does JavaScript support automatic type conversion? 
Yes, JavaScript supports automatic type conversion.

JavaScript Intermediate Interview Questions

21. What are all the looping structures in JavaScript ?
while loop: A while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.
for loop: A for loop provides a concise way of writing the loop structure. Unlike a while loop, for statement consumes the initialization, condition and increment/decrement in one line thereby providing a shorter, easy to debug structure of looping.
do while: A do-while loop is similar to while loop with the only difference that it checks the condition after executing the statements, and therefore is an example of Exit Control Loop.

22. How can the style/class of an element be changed?
To change the style/class of an element there are two possible ways. We use document.getElementByID method
document.getElementById("myText").style.fontSize = "16px;
document.getElementById("myText").className = "class";

23. Explain how to read and write a file using JavaScript?
The readFile() functions is used for reading operation.
readFile( Path, Options, Callback)
The writeFile() functions is used for writing operation.
writeFile( Path, Data, Callback)

24. What is called Variable typing in JavaScript ?
The variable typing is the type of variable used to store a number and using that same variable to assign a “string”.
Geeks = 42;
Geeks = "GeeksforGeeks";


25. How to convert the string of any base to integer in JavaScript?
In JavaScript, parseInt() function is used to convert the string to an integer. This function returns an integer of base which is specified in second argument of parseInt() function. The parseInt() function returns Nan (not a number) when the string doesn’t contain number.

26. Explain how to detect the operating system on the client machine?
To detect the operating system on the client machine, one can simply use navigator.appVersion or navigator.userAgent property. The Navigator appVersion property is a read-only property and it returns the string that represents the version information of the browser.

27. What are the types of Pop up boxes available in JavaScript?
There are three types of pop boxes available in JavaScript.
  • Alert
  • Confirm
  • Prompt
28. What is the difference between an alert box and a confirmation box?
An alert box will display only one button which is the OK button. It is used to inform the user about the agreement has to agree. But a Confirmation box displays two buttons OK and cancel, where the user can decide to agree or not.

29. What is the disadvantage of using innerHTML in JavaScript?
There are lots of disadvantages of using the innerHTML in JavaScript as the content will replace everywhere. If you use += like “innerHTML = innerHTML + ‘html’” still the old content is replaced by HTML. It preserves event handlers attached to any DOM elements.

30. What is the use of void(0) ?
The void(0) is used to call another method without refreshing the page during the calling time parameter “zero” will be passed.



source :[Internet]


Comments

Popular posts from this blog

What is JDK, JRE and JVM?

What are JDK, JRE, and JVM: JDK :- Java Development Kit (in short JDK) is Kit which provides the environment to Develop and execute(run ) the Java program. For eg. You(as Java Developer) are developing an accounting application on your machine, so what do you going to need into your machine to develop and run this desktop app? You are going to need  J-D-K  for that purpose for this you just need to go to the official website of sun or oracle to download the latest version of JDK into your machine. Hence, JDK is a kit(or package) which includes two things i) Development Tools(to provide an environment to develop your java programs) and ii) JRE (to execute your java program). JDK is only used by Java Developers. JRE: - Java Runtime Environment (to say JRE) is an installation package which provides an environment to only run(not develop) the java program(or application)onto your machine. For eg(continuing with the same example) after developing your accounting ap...

The Future of Java Developers in the Age of AI and ChatGPT

  In today's rapidly evolving tech landscape, AI tools like ChatGPT are becoming more integrated into the software development process. As a Java developer, whether you're just starting out or have years of experience, you might wonder: How can I stay relevant and succeed in the age of AI? In this post, we'll explore practical strategies to ensure you not only survive but thrive as a Java developer in this AI-driven world. 1. Embrace AI as a Tool, Not a Threat AI isn't here to replace you—it's here to help you. Tools like ChatGPT can automate repetitive tasks, assist with coding challenges, and even generate code snippets, allowing you to focus on more complex and creative aspects of development. For Freshers: Use AI tools to learn and understand Java more quickly. Let them assist you in writing code, but make sure you're also learning the logic and concepts behind it. For Experienced Developers: Integrate AI tools into your workflow to enhance productivity. L...

What are the best opportunities for java in 2021?

Firstly, Java is widely used for building enterprise-scale web applications. Java is known to be extremely stable and so, many large enterprises have adopted it. If you are looking for a development based job at a large organization, Java is the language that you should learn. It is widely used in Android App Development. So if anyone is willing to find a career in Android App Development, he/she should have an intermediate level of experience in Java. Some of the different domains where Java is used widely are as follows: Financial services:  It is used in server-side applications. Big Data:  Hadoop MapReduce framework is written using Java. Banking:  To deal with transaction management. Stock market:  To write algorithms as to which company they should invest in. Retail:  Billing applications that you see in a store/restaurant are completely written in Java. Android:  Applications are either written in Java or use Java API. Scientific and Research Communi...