“JS Perguntas da entrevista” Respostas de código

Entrevista de JavaScript

1) What are the Various data tyes in javaScript

var age = 18;                           // number 
var name = "Jane";                      // string
var name = {first:"Jane", last:"Doe"};  // object
var truth = false;                      // boolean
var sheets = ["HTML","CSS","JS"];       // array
var a; typeof a;                        // undefined
var a = null;                           // value null

2) What is callback 
// 
// callback function is a function passed into another function as an argument.
// Don't call me, I will call you.

function greeting(name) {
  alert('Hello ' + name);
}

function processUserInput(callback) {
  var name = prompt('Please enter your name.');
  callback(name);
}

processUserInput(greeting);

3) Difference between Function Declaration vs Function Expression?

// Function Declaration
// Declare before any code is executed.
// You cade can run because, no call can be called until all expression is loaded 
// Declated as a seprate statement within the main JavaScript code

console.log(abc())

function abc(){
return 5;
}

// Function Expression
// Created when the execution point reaches it. can be used only after that.
// created inside an expression or some other construct
 
var a = function abc(){
return 5;
}
console.log(a)


4) What is cookies, sessionStorage, localStorage.

// cookies in created by a server and stored on client-side.
// it is used to remember information for later, so It can give better recommendation for the user.

// SessionStorage and localStorage are similar except

// SessionStorage data is cleared when the page session ends.

// localStorage data stay until the user manually clears the browser or until your web app clears the data.

5) What are Closures

// Is a feature where the inner function has access to the outer function variable.
// The inner function inner_func can access its variable 'a' and the outer variable 'b'. 


function outer_func()
{
	var b = 10;
	function inner_func(){
	var a = 20;
	console.log(a+b);
}
return inner;
}


6) what are the Import and Export in javaScript

// You can share functions, objects, or primitive values from one file by using export and access it from a different file by using import.

// Export 
export const name = "Jesse";

// or 

const name = "Jesse";
export {name};

 // or 

const message = () => {
const name = "Jesse";
return 'My name is' + name ';
};
export default message;


// import
import { name, age } from "./person.js";

// or 

import message from "./message.js";


7) What is the Difference between Undefined, undeclared, Null

// undefined means that the variable has not been declared, or has not been given a value.
// Undefined is used for unintentionally missing values.
var name;
console.log(name);


// Undeclared means the variable does not exist in the program at all.
console.log(name);


// Null used for intentionally missing values. It contains no value.

8) How to remove Duplicates from javaScript Array?

// By using the filter method

let chars = ['A', 'B', 'A', 'C', 'B'];

let uniqueChars = chars.filter((c, index) => {
    return chars.indexOf(c) === index;
});

console.log(uniqueChars);

// [ 'A', 'B', 'C' ]


Yafet Segid

Perguntas para entrevistas de JavaScript

var obj = {
    name:  "vivek",
    getName: function(){
    console.log(this.name);
  }
}
        
obj.getName();
Green Team

JS Perguntas da entrevista

function sumOfThreeElements(...elements){
  return new Promise((resolve,reject)=>{
    if(elements.length > 3 ){
      reject("Only three elements or less are allowed");
    }
    else{
      let sum = 0;
      let i = 0;
      while(i < elements.length){
        sum += elements[i];
        i++;
      }
      resolve("Sum has been calculated: "+sum);
    }
  })
}
Strange Sable

JS Perguntas da entrevista

function addFourNumbers(num1,num2,num3,num4){
  return num1 + num2 + num3 + num4;
}

let fourNumbers = [5, 6, 7, 8];


addFourNumbers(...fourNumbers);
// Spreads [5,6,7,8] as 5,6,7,8

let array1 = [3, 4, 5, 6];
let clonedArray1 = [...array1];
// Spreads the array into 3,4,5,6
console.log(clonedArray1); // Outputs [3,4,5,6]


let obj1 = {x:'Hello', y:'Bye'};
let clonedObj1 = {...obj1}; // Spreads and clones obj1
console.log(obj1);

let obj2 = {z:'Yes', a:'No'};
let mergedObj = {...obj1, ...obj2}; // Spreads both the objects and merges it
console.log(mergedObj);
// Outputs {x:'Hello', y:'Bye',z:'Yes',a:'No'};
Strange Sable

var x = 21; var myfunction = function () {console.log (x); var x = 20; }; myFunction ();

var x=21;
var myFunction = function(){
console.log(x);
var x= 20;
};
myFuntion();
Busy Bat

Perguntas da entrevista de quebra -cabeça JavaScript

// What is the Output var Employee = {    company: 'xyz'}var emp1 = Object.create(Employee);delete emp1.companyconsole.log(emp1.company);// Output  'xyz'
Spotless Starling

Respostas semelhantes a “JS Perguntas da entrevista”

Perguntas semelhantes a “JS Perguntas da entrevista”

Mais respostas relacionadas para “JS Perguntas da entrevista” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código