JavaScript Interview Questions
This page consists of JavaScript interview questions and answers.
JavaScript is a light-weight, browser-based and platform independent scripting language.
Yes. NodeJS is one example.
JavaScript was provided by NetScape and Microsoft developed their own JavaScript and named it JScript to avoid copyright issues.
They are similar but with different names.
console.log("Hello World");
For this we use the script
tag and set the type
attribute to text/javascript
.
The following code can be added in a HTML file.
<script type="text/javascript">
console.log("Hello World");
</script>
Note! In newer browsers we can omit the type
attribute.
For this we use the script
tags and set the src
attribute to the JavaScript file path that we want to include.
In the following example we are including a JavaScript file from the js directory.
<script src="js/script.js"></script>
We save JavaScript file using the .js
extension.
For this we can use document.write()
and pass the required string.
document.write('<p>Hello World</p>');
For this we create an instance of the Date
.
var d = new Date();
console.log(d);
The above code will give us output in the following format.
Wed Jan 01 2014 06:59:08 GMT+0530 (IST)
For this we can use JavaScript alert()
and pass the string Hello World
.
alert('Hello World');
ADVERTISEMENT