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