JavaScript Questions

What is scripting language?
Scripting languages are used to develop dynamic web pages.
What is JavaScript?
JavaScript is an object-oriented and client-side scripting language used to develop dynamic web pages.
What are the advantages of JavaScript?
  • Provide rich interface
  • Client-side security
  • Reduce load on servers
What is <script> and <noscript>?
<script> tag is used to embedded JavaScript code with HTML when your browser supports script code, if not supported <noscript> will execute.
Difference between var, let and const?
var let const
Can be declared without initialization. Can be declared without initialization. Cannot be declared without initialization.
undefined is the default value of uninitialized variable. undefined is the default value of uninitialized variable. Cannot be declared without initialization.
Scope of var variable is global or local. Scope of let variable is global, local or block. Scope of const variable is global, local or block.
It allows re-declaration in same scope. It doesn't allow re-declaration in the same scope. It doesn't allow re-declaration in the same scope.
Difference between == and ===?
== is compares two values are equal whereas, === is compares both values and datatypes are equal.
Difference between != and !==?
!= is compares two values are not equal whereas, !== is compares both values and datatypes are not equal.
Difference between for, for-in and for-of?
for is an iterative statement with initial value, condition and updation.
for-in is an iterative statement works only on sequence types and returns index or key of item in sequence.
for-of is an iterative statement works only on sequence types and returns item in sequence.
What are the datatypes in JavaScript?
Number, String, Boolean, null, undefined
How to define function in JavaScript?
function functionName(){
    //Function Block
}
What is self-invoking function?
Self-invoking function is a type of function in JavaScript which is automatically invoked or called after its definition.
(function(){
    //Function Block
})()
What is arrow function?
An arrow function is also called as anonymous function which means a function without name but assigned to variable.
What is an Array?
An Array is a built-in object which is a collection of different type of elements.
Explain shift() and unshift() methods of Array?
shift() is used to remove an element from the beginning of the array.
unshift() is used to add one or more elements at the beginning of the array.
What is an Object and how to define it?
An Object is a collection of properties, property is nothing but key and value pair. Here, value may be a function also in such case function is called as method.
var userobj = {
  property1: value,
  property2: value,
  property3: function () {
    //Function Block   }
}
What is "use strict"?
"use strict&qupt; is a literal mentioned at the starting of the program this allows users to use only declared variables, shows error otherwise.
What is module?
A module is a small piece of code saved in a separate file and import where you need it.
What is the use of window object?
A window object is used to open window on current window.
What is DOM?
DOM – Document Object Model is a programming interface for a web document.
What is the use of document object?
DOM is used to allow programs that dynamically access and update the content, structure and style of a document.
How to access HTML element with document object?
First identify HTML element with id attribute and access with document.getElementById('idName') method.
How to create an element with document object?
Using document.createElement('htmlelement')
How to add child elements to parent element with document object?
Using append() and appendChild() methods.
Difference between append() and appendChild() methods?
append() methods allow nodes and strings to append whereas, appendChild() methods allows only node to append.
How to remove attribute with document object?
node.removeAttribute(attributeName)
How to control style with document object?
document.getElementById('idName7apos;).style.property = value