0 votes
in JavaScript by
1.Try-it-out - Function for Fibonacci Series
Welcome to To generate Fibonacci sequence new
process.stdin.resume();
process.stdin.setEncoding('utf-8');
var __input_stdin = "";
var __input_stdin_array = "";
var __input_currentline = 0;
process.stdin.on('data', function(data) {
    __input_stdin += data;
});
/*
 * Complete the function below.
 */
function fibonacciSequence(input) {
    //Type your code here.
        var n1=0;
        var n2=1;
        var out=[];
        if(input==1)
            out.push(n1);
        else if(input==2)
            out.push(n1,n2);
        else{
            out.push(n1,n2);
            for(var i=0;i<=input-2;i++){
                var n3=n2+n1;
                n1=n2;
                n2=n3;
                out.push(n3);
            }
        }
        return out;
}
var fs = require('fs');
var wstream = fs.createWriteStream(process.env.OUTPUT_PATH);
process.stdin.on('end', function() {
    __input_stdin_array = __input_stdin.split("\n");
    var input;
    var input = parseInt(__input_stdin_array[__input_currentline].trim(), 10);
    __input_currentline += 1;
    res = fibonacciSequence(input);
    for(var res_i = 0; res_i < res.length; res_i++) {
        wstream.write(res[res_i]+"\n");
    }
    wstream.end();
});
image
2.Try-it-out - DOM - User Registration Details
Welcome to To read the user registration details
File Name - index.js
function myFunction() {
 var name = document.getElementById("myname").value;
 var phone = document.getElementById("myphone").value;
 var country = document.getElementById("mycontry").value;
 var email = document.getElementById("mymail").value;
 var result = name + "," + phone + "," + country + "," + email;
 alert(result);
 return result;
}
image
 
3.Try-it-out - DOM - Create Drop Down Country Field
Welcome to To create a drop down Country field
File Name - index.js
function runList(){
   var select = document.getElementById("list");
   var newOption = document.createElement("option");
   newOption.text = document.getElementById("txtbox").value;
   select.add(newOption);
}
image
 
4.Try-it-out - Generate random characters
Welcome to To generate Random Character id
File Name - index.js
function stringGen()
{
   var text = "";
   var val = document.querySelector("#num").value;
   var possible = "ABCDEFGHIKLMNOPQRSTVXYZabcdefghijklmnopqrstuvwxyz01234546789"
   for (var i=0;i< val; i++)
   text += possible.charAt(Math.floor(Math.random() * possible.length));
   return text;
}
image
 
5.Try-it-out - Simple Calculator
Welcome to To create a simple calculator
File Name - index.js
function update(value) {
    //Type the code here.
    document.getElementById('screen').value += value;
}
function result() {
    //Type the code here.
    document.getElementById('screen').value = eval(document.getElementById('screen').value);
}
function form_reset() {
    //Type the code here.
   document.getElementById('screen').value = "";
}
image
 

JavaScript Interview Questions for Freshers

1. What are the different data types present in javascript?

To know the type of a JavaScript variable, we can use the typeof operator.

1. Primitive types

String - It represents a series of characters and is written with quotes. A string can be represented using a single or a double quote.

Example :

var str = "Vivek Singh Bisht"; //using double quotes
var str2 = 'John Doe'; //using single quotes
  • Number - It represents a number and can be written with or without decimals.

Example :

var x = 3; //without decimal
var y = 3.6; //with decimal
  • BigInt - This data type is used to store numbers which are above the limitation of the Number data type. It can store large integers and is represented by adding “n” to an integer literal.

Example :

var bigInteger =  234567890123456789012345678901234567890;
  • Boolean - It represents a logical entity and can have only two values : true or false. Booleans are generally used for conditional testing.

Example :

var a = 2;
var b =  3;
var c =  2;
(a == b) // returns false
(a == c) //returns true
  • Undefined - When a variable is declared but not assigned, it has the value of undefined and it’s type is also undefined.

Example :

var x; // value of x is undefined
var y = undefined; // we can also set the value of a variable as undefined
  • Null - It represents a non-existent or a invalid value.

Example :

var z = null;
  • Symbol - It is a new data type introduced in the ES6 version of javascript. It is used to store an anonymous and unique value.

Example :

var symbol1 = Symbol('symbol');
  • typeof of primitive types :
typeof "John Doe" // Returns "string"
typeof 3.14 // Returns "number"
typeof true // Returns "boolean"
typeof 234567890123456789012345678901234567890n // Returns bigint
typeof undefined // Returns "undefined"
typeof null // Returns "object" (kind of a bug in JavaScript)
typeof Symbol('symbol') // Returns Symbol

2. Non-primitive types

  • Primitive data types can store only a single value. To store multiple and complex values, non-primitive data types are used.
  • Object - Used to store collection of data.
  • Example:
// Collection of data in key-value pairs

var obj1 = {
   x:  43,
   y:  "Hello world!",
   z: function(){
      return this.x;
   }
}
      
// Collection of data as an ordered list
     
var array1 = [5, "Hello", true, 4.1]; 

2. What are the differences between JavaScript and Java?

Java is an object-oriented and structured programming language, which helps to run web pages on different platforms. The java code should be compiled on the compiler. JavaScript is an object-oriented scripting language. In which, the scripts are optimized for both server and client-side. Javascript is introduced to perform HTML pages.

3. Name the different types of JavaScript data?

JavaScript data are of the following types - 

  1. String  
  2. Function  
  3. Boolean  
  4. Object  
  5. Number 
  6. Null

4. What is the definition of global variables? In what way, these variables are declared?  

A global variable is a special kind of variable in JavaScript. This variable is easy to use and also available across the entire length of the JavaScript code. Mainly, the var keyword is used whether to declare a global or local variable.

5. What is the definition of the prompt box?  

The Input provided by any user in the JavaScript is entered with the help of a prompt box. While putting forward the data or the input, the prompt box allows the user to do this with the help of a text box. To include the number, a label box is also used.

6. Name the different types of groups of data types that are used in JavaScript and define them?

There are two basic groups of data types -  

  • Reference type- These are complex types of data that can mainly include dates and strings. 
  • Primitive type- These are the types of data that include numbers

7. Name the problems that are associated with the use of global variables?

Even though global variables are easy to use, these have some shortfalls. While using this type of variable, the problem of clashing the variable names of different global and local scope occurs. The code that is often relied on the global variable also gets difficult to be tested and debugged.

8. Which Company developed JavaScript?

Netscape company had developed the JavaScript Programming Language.

9. What type of variables do we use in JavaScript?

We use object data type variables in JavaScript.

10. What is meant by NULL in JavaScript?

If no value has been given to the variable then, it is called a null object (or) null value.

11. Which property is used to detect the operating system in a cloud machine?

 Navigator. platform String property is used to detect issues of the operating system in a cloud.

12. What are the pop-ups available in JavaScript?

 The popups available in JavaScript are Alert, Prompt, and Confirm.

13. What is the Different between Null and Undefined?

Both null and undefined have an empty value, but the difference between these two is:

  • In an undefined case, we don't assign a value for the variable.
  • In the null case, we assign a zero value to the variable.

14. What are the ways used to read and write a file in JavaScript?

Two ways are available to read and write a file, they are:

  • JavaScript Expressions
  • Webpages and Active X objects

15. How to create an array in JavaScript?

Arrays are used to store various values in a single variable.

Defining an array in JavaScript:

var mobile = [“Oppo”, “ Samsung”, “Vivo”]

By using a new keyword:

Var mobile = new array(“ Oppo”, “Samsung'', “Vivo”)

16. Mention the different types of functions that are supported by JavaScript? Define each of them?

There are two types of functions that are supported by JavaScript. They are -

  • Anonymous function- This type of function generally has no name and this is the difference between it and a normal function.  
  • Named function- On the other hand, this function is named properly and specifically.

17. What is mean by “this” in javaScript?

“This” keyword is an object in a javascript, where it refers to. It has different values at different stages, whereas in method “this” is used as an owner object and in function, it is called a global object.

18. How to submit a form in JavaScript?

 In JavaScript, we can submit a form by using

document.form[0].submit();

19. Does JavaScript support Automatic type conversion?

 Automatic type conversion is supported by javascript and usually, the developers of javascript use the automatic type conversion method.

20. How to create objects in JavaScript?

As JavaScript is an object-oriented scripting language, it is very easy to create objects in JavaScript.

var std = { name: “ David”,  age: 16, id: 364 };

21. What is the difference between the scope of the variables in JavaScript?

JavaScript variables have different scopes. The scope of the variable is nothing but the functionality of the variable.

  • Global variables- Global variables consist of global scope whereas these variables can be utilized in the whole program repeatedly.
  • Local Variables- Local variables have no scope and are used only once in the whole program.

22. What is mean by name function?

The named function in JavaScript defines the name as well as the value of a function. It is defined by using the keyword 

"function”

function named()
{
// write code
}

23. What is argument objects in javascript?

The JavaScript variable represents the arguments that can be passed to the function. By using, ‘type of’ operator we can represent the argument objects.

Example:

function  fun(a)
{
console.log(typrof a, arguments.length);
}
fun(7); 
fun( "2", "3”, "4");
fun();

24. What is the meaning of the word 'callback'?

The callback is a typical function of JavaScript that can be passed as an option or argument of JavaScript. Sometimes, callbacks can also be termed as simple events. Users are given calls to react to different kinds of triggered situations.

Advanced JavaScript Interview Questions

25. List out different types of errors in JavaScript?

Different types of errors in JavaScript are:

  • Run time errors- errors occurred due to misrepresentation of HTML commands.
  • Load time errors- errors that occurred at the time of web page loading are known as load time errors. These errors may occur due to improper syntaxes
  • Logical errors- logical errors may occur due to improper logical performance of the function.

1 Answer

0 votes
by

26. How to get an element by class in JavaScript?

By using  method Document.getElementsByclass name(), we can get elements in class name.

27. What is closure?

The closure is a primary mechanism to private the data items. Closures give access to the outer function’s scope from the inner function scope. Closures are created for every function in JavaScript. To define a closure, create a function inside another function to expose it. 

28. What is the “===” operator?

“===” is a strict equality operator, returns a true value, if the two operands have the same value.

29. How can we read the properties of JavaScript?

Using dot(.) notation we can read and write the properties of JS.

30. What is the difference between Attributes and properties?

  • Attributes- Attributes provide the information about the details given to objects like name, age, id, etc,
  • Properties- Properties give information about the values given to the objects.

31. What are the possible ways to define a variable in JavaScript?

There are three possible ways to declare a variable in JavaScript are:

  • Var- variables and values of variables can be declared to the Variable statement by Variable statement. Example - var b = 20;. Declaration of variables should be done before the execution of code.
  • Const- A constant variable is assigned with one value only once before the execution of code.
  • let- If let statements are used in the variable declaration, the variable values can be reassigned before the execution of code.

32. What are the terms BOM and DOM in JavaScript?

  • BOM- BOM is a Browser Object Model, in which the window object is supported by all the browsers. The JavaScript objects, variables, and functions also become members of the window object. This model deals with the objects of browsers like location, navigator, history, and screen.
  • DOM- DOM is a Document Object Model in JavaScript that helps to access document and HTML elements. When a web page is loaded the browser creates a DOM for the page. All the objects on the page all arranged in order.

33. Explain the terms array slice() and array splice()?

  1. Array slice() method removes the array items from the array and reforms the removed items into a new array. The selected items through an array slice() method are removed from the array and formed as another new array. 
  2.  array splice() method removes the items of the selected array from the array and does not form another array.

34. Define some of the methods in JavaScript?

  • confirm() -   Helps to get confirm dialog box including messages.
  • open() -   Helps to open the new window.
  • alert() -  This method displays the alert box with messages
  • close() -  Heps to close the window.
  • setTimeout() - This method helps to perform certain operations after a specified time like evaluating expressions and calling functions.

35. Explain what is NaN() function?

A NAN (not a number) method is used to return a true value if the variable has no number.

function number(num)
{
if(isNaN(num))
{ 
returns if it is not a number;
}
return if it is a number;
}

36. Explain View state and Session state?

  • View State- The particular point of time where the user spent on only a page of the session is called view state
  • Session State- Where the browser or user spends on all pages of the application is called session state.

37. How to make an array empty?

Let us consider an array

Var array  =  [ “1”, “2”, “3,'' “4” ];
We consider four methods to empty an array
1. array  = []
2. array.length = 0;
3. array.splice(0, array.length);
4. while (array.length)
{
array.pop();
}

38. Define the mechanism of the type of operator?

The type of operator is basically just the unary operator that is used before the single operand. The value indicates the operand's data type. The type includes Boolean, number, and string.

JavaScript Interview Questions for Experienced

39. Explain about MUL function in JavaScript?

MUL is a multiplication function. The multiplication of numbers can be done as a value is defined in the function and the value is returned by another function and the process goes on.

Example:

function  mul(a)
{
return function(b)
{
return function(c)
{
return  a*b*c;
};
};
}

40. Can redirection of a page is possible in JavaScript?

Redirection of the page is possible in JavaScript. By using two ways we can redirect a page to other pages, they are:

  • Location.href- This is one of the ways to redirect a page. By this, we can get back access to the document. 
window.location.href  = (“http//jaquar.com”);
  • Location.replace- In this, we can’t get access back the actual document.
window.location.href  = (“http//jaquar.com”);

41. How to add and remove properties from objects?

By using,object.property_name The = value we can add a property to the JS object

By using, deleteobject.property_name is used to remove the property from the JS object.

42. How to Validate a form in JavaScript?

We can validate a variable by using the following script

<script>
function validateform()
{
var fullname  = document.firstform.fullname.val;
var pwd  =  document.pwd.val;

if(fullname==null || fullname=="")
{
alert("fullname should be filled")
 return true;  
}
else if(password.length<5)
alert("pwd must me upto 5 characters long"):
return false;
}
}
</script>
<body>
<form name =" firstform" method= "post"  action ="xyz.jpg" onsubmit =" return validateform()">
fullname = input type= "text" fullname ="name">
<br/>
pwd  = inputtype="pwd" name="pw">
<br/>
<inputtype="submit"value"register">
</body>
</form>

43. How to represent the date object in JavaScript?

Date object in JavaScript helps to get information about the day, month, and year. By using date object we can set the timer on the screen.

function display() 
{
var date = new date();
var day = date.getday();
var month= date.getmonth()+1;
Var year = date.getyear();
doc.write("date is: "+day+"/"+month+"/"+year+");
}
display();

44. What is meant by the debugger in JavaScript?

Debugger keyword in JavaScript helps in setting a breakpoint in the code itself. The program will stop executing code where the debugger keyword is applied in the program.

function display()
{
a = 10;
b  = 20;
c  = a+b;
debugger;
doc.write(c);
doc.write(a);
}
display();

45. What is the use of a Weakmap object in JavaScript?

Weakmap is similar to a collection of objects like a map. If the weak map object is set to a process, it considers each element as a key object and that key object will have a weak reference.

function display()
{
var wm  = new WeakMap();
var object1 = {};
var object2 = {};
var object3 = {};
wm.set(object1, "AngularJS");
wm.set(object2, "ReactJS");
wm.set(object3, "VueJS");
doc.writeIn(wm.has(object3));
}
display();

46. Name some of the JavaScript frameworks?

The applications written in JavaScript are known as JavaScript frameworks. These frameworks are a different form of JavaScript libraries and flows. Here is a list of some important frameworks, they are:

  • Angular JS
  • Vue 
  • React
Related Article: Best JavaScript Frameworks

47. Explain about escape characters?

Espace characters are used to handle the special characters without breaking the code in javascript. It uses a black slash for different characters like single and double quotes, newline, and so on

  • ’ single quote
  •   backslash
  • ’’ double quote
  • n  newline
  • b  backspace
  • t  tab
  • f   form feed

48. Write about number objects?

Number objects help to represent the number of values to the variables. The values may be floating-point or integer. In JavaScript, the floating points are represented by using the IEEE standard.

function display()
{
var a = 10;
var  b = 0.7;
var  c =  11d5;
doc.write(a+" "+b+" "+c+");
}
display();

49. How set object is used in JavaScript?

Set objects are used to store different values to the elements. The values may be reference or primitive values.

function display()
{
var set = new Set();
set.add( "Angular JS":;
set.add(" Vue");
set.add("React JS);
for(set the elements of set)
{
doc.writeIn(elements):
}
}
display();

50. How to calculate the Fibonacci series in JavaScript?

Fibonacci series is a series of numbers, in which every value is the sum of the preceding two numbers starting with 0 and 1.

Example - 0,1,1,2,3,5,8,13,21,34……..

function fibonacci(n);
{
var x=o, y=1;
for  (var i=0;  i < n;  i++);
{
var   temp = x+y;
x  = y;
y  = temp;
}
return  x;
}

Related questions

0 votes
asked Jul 2, 2022 in Git by sharadyadav1986
0 votes
asked Jun 26, 2022 in Azure Virtual Network by sharadyadav1986
...