“Pytania do wywiadu JavaScript” Kod odpowiedzi

Przykład JavaScript Anagram

function anagram(name, words) {
	var a = name.replace(/\s/g,'').toLowerCase().split('').sort().join('');
	var b = words.join('').split('').sort().join('');
	return a == b;
}
Restu Wahyu Saputra

Wywiad 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

Pytania do wywiadu JavaScript

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

Pytania o wywiad JS

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

zadawanie pytań JavaScript w konsoli

var readline = require('readline');

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question("What do you think of node.js? ", function(answer) {
  console.log("Thank you for your valuable feedback:", answer);

  rl.close();
});
Terrible Turkey

Pytania do wywiadu JavaScript

var currentDate = new Date();
var day = currentDate.getDate();
Var month = currentDate.getMonth() + 1;
var monthName;
var hours = currentDate.getHours(); 
var mins = currentDate.getMinutes(); 
var secs = currentDate.getSeconds(); 
var strToAppend;
If (hours >12 )
{
    hours1 = "0" + (hours - 12);
strToAppend = "PM";
}
else if (hours <12)
{
    hours1 = "0" + hours;
    strToAppend = "AM";
}
else
{
    hours1 = hours;
    strToAppend = "PM";
}
if(mins<10)
mins = "0" + mins;
if (secs<10)
    secs = "0" + secs;
switch (month)
{
    case 1:
        monthName = "January";
        break;
    case 2:
        monthName = "February";
        break;
    case 3:
        monthName = "March";
        break;
    case 4:
        monthName = "April";
        break;
    case 5:
        monthName = "May";
        break;
    case 6:
        monthName = "June";
        break;
    case 7:
        monthName = "July";
        break;
    case 8:
        monthName = "August";
        break;
    case 9:
        monthName = "September";
        break;
    case 10:
        monthName = "October";
        break;
    case 11:
        monthName = "November";
        break;
    case 12:
        monthName = "December";
        break;
}

var year = currentDate.getFullYear();
var myString;
myString = "Today is " + day +  " - " + monthName + " - " + year + ".<br />Current time is " + hours1 + ":" + mins + ":" + secs + " " + strToAppend + ".";
document.write(myString);
Bewildered Buzzard

Odpowiedzi podobne do “Pytania do wywiadu JavaScript”

Pytania podobne do “Pytania do wywiadu JavaScript”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu