What is JavaScript build tools like grunt or gulp

 Gulp uses Node. js module stream, whereas Grunt uses file system

The difference between these two task runners is that Grunt is file-oriented and creates temporary files at runtime, while Gulp handles processes in memory and writes them immediately to the target file.

What is difference b/w export and import with Example in Javascript

export and import  are used for modularization of code in JavaScript.

 Export is used to make values and functions defined in a module available to other modules that import it, while

 Import is used to import the exported values and functions into another module.

Native JavaScript Modules

Modules in JavaScript use the import and export keywords:

  • import: Used to read code exported from another module.
  • export: Used to provide code to other modules.
Export Example--

you can say below code file name is functions.js

export function sum(x, y) {
  return x + y
}

export function difference(x, y) {
  return x - y
}

export function product(x, y) {
  return x * y
}

export function quotient(x, y) {
  return x / y
}


Import Example:-

import { sum, difference, product, quotient } from './functions.js'

const x = 10
const y = 5

document.getElementById('x').textContent = x
document.getElementById('y').textContent = y

document.getElementById('addition').textContent = sum(x, y)
document.getElementById('subtraction').textContent = difference(x, y)
document.getElementById('multiplication').textContent = product(x, y)
document.getElementById('division').textContent = quotient(x, y)

CallBack Function Example With Demo

 Definitaion:- Functions that are used as an argument to another function are called callback functions.

Code:-

function divideByHalf(sum){
  console.log(Math.floor(sum / 2));
}

function multiplyBy2(sum){
  console.log(sum * 2);
}

function operationOnSum(num1,num2,operation){
  var sum = num1 + num2;
 // console.log(sum)
  operation(sum);
}

operationOnSum(33divideByHalf); // Outputs 3

operationOnSum(55multiplyBy2); // Outputs 20

Happy Diwali



CPU vs GPU Architecture

  CPU vs GPU Architecture CPU (Central Processing Unit) and GPU (Graphics Processing Unit) have distinct architectural differences, optimize...

Best for you