Javascript Interview Que
Javascript Interview Que
Javascript Interview Que
It was designed to
build dynamic web pages at first. A script is a JS program that may be added to the HTML of any web page. When the page
loads, these scripts execute automatically.
A language that was originally designed to build dynamic web pages may now be run on the server and on almost any device
that has the JavaScript Engine installed.
After HTML and CSS, JavaScript is the third biggest web technology. JavaScript is a scripting language that may be used to
construct online and mobile apps, web servers, games, and more. JavaScript is an object-oriented programming language that is
used to generate websites and applications. It was created with the intention of being used in a browser. Even today, the server-
side version of JavaScript known as Node.js may be used to create online and mobile apps, real-time applications, online
streaming applications, and videogames. Javascript frameworks, often known as inbuilt libraries, may be used to construct
desktop and mobile programs. Developers may save a lot of time on monotonous programming jobs by using these code
libraries, allowing them to focus on the production work of development.
1) What is JavaScript?
As mentioned above, Javascript is no longer just a lightweight language. It has become a powerful,
object-oriented, interpreted programming language that adds dynamic capabilities to HTML
pages. All the popular web browsers use it as a scripting language. It also is used in the backend to
create services in platforms like NodeJS.
<head>
</script>
</head>
You can also link in to the HTML file, like in this example:
<head>
</head>
/* This is a
In older versions of JavaScript, you declared a variable using the keyword “var”. In modern JavaScript, “var” has been replaced with
the keyword “let”. Because of this, the distinction between global and local variables becomes more sharply defined. You declare a
variable using “let”:
If a variable is not within a function, an if block, or a loop, the variable is global in scope.
Undefined
Null
Boolean
String
Symbol
Number
Object
var x;
var x = null;
Both are comparison operators. The difference between both the operators is that “==” is used to
compare values whereas, “ === “ is used to compare both values and types.
Example:
var x = 2;
var y = "2";
(x == y) // Returns true since the value of both x and y is the same
(x === y) // Returns false since the typeof x is "number" and typeof y is
"string"
1. From the very beginning, the 'var' keyword was used in JavaScript programming whereas the keyword 'let' was just
added in 2015.
2. The keyword 'Var' has a function scope. Anywhere in the function, the variable specified using var is accessible but in
‘let’ the scope of a variable declared with the 'let' keyword is limited to the block in which it is declared. Let's start with
a Block Scope.
3. In ECMAScript 2015, let and const are hoisted but not initialized. Referencing the variable in the block before the
variable declaration results in a ReferenceError because the variable is in a "temporal dead zone" from the start of the
block until the declaration is processed.
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.
Netscape developed JavaScript and was created by Brenden Eich in the year of 1995.
Yes, it is possible to break the JavaScript code into several lines in a string statement. It can be broken by using the backslash ‘\’.
For example:
Geeks =
gfg + GFG;
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() {
geeks.textContent = "Geeksforgeeks";
geeks.setAttribute('class', 'note');
document.body.appendChild(geeks);
</script>
</body>
</html>