Skip to main content

Posts

Namaste Javascript Study Notes -2

  Hello, These are the study notes of the famous javascript course  Namaste Javascript .  I was creating this for my personal study but later thought that it might also help others. If you are confused or not getting any point do watch the course. You make also like this Namaste Javascript  Study Notes -1. Functions: Function statement aka Function Declaration  function a(){ console.log("a called") } Function Expression var b=function(){ console.log("b called") } The difference between these 2 types is hoisting. Function statement can be called above its declaration while in the case of function expression it should be called after declaration else it will throw an error. Anonymous Function  function(){ console.log("b called") } Function without a name and it does not have its own identity as if you run it like this it will give an error. It is used where functions are used as values i.e we can assign them to a variable so that become function expressions.

JavaScript functions. Why they are called as first class citizens or functions?

These are the notes taken from the famous javascript course  Namaste Javascript .  If you are  not getting any point do watch the course. I was creating this for my personal study but later thought that it might also help others. Let's begin, Different ways to define a function in javascript: a)Function statement aka Function Declaration : function a(){ console.log("a called") } b)Function Expression: var b=function(){ console.log("b called") } The difference between these 2 types( Function statement and  Function Expression ) is hoisting. Function statement can be called above its declaration while in the case of function expression it should be called after declaration else it will throw an error. c)Anonymous Function: function(){ console.log("b called") } Function without a name and it does not have its own identity as if you run it like this it will give an error. It is used where functions are used as values i.e we can assign them to a variable so

Namaste Javascript Study Notes -1

Hello, These are the study notes of the famous javascript course Namaste Javascript . I was creating this for my personal study but later thought that it might also help others. If you are confused or not getting any point do watch the course. 1)Javascript execution context. Execution context is created when we run any js program. This execution context is called a global execution context and is pushed inside a stack name execution stack. It has 2 phases, 1)Memory phase: Where memory is allocated to variables and functions. Undefined is allocated to variables and function is stored as it is with its code. 2)Code Phase: Here values are assigned to a variable and if any function calls then again a separate execution context is created for that function which again has 2 phases memory and code. and it goes on the same for any function call invocation. So whenever an execution context is created it is pushed inside an execution stack. For the first time, a global execution context is cr

Deploy static angular website project on AWS S3 bucket latest.

 Hello, In this article we will see how to deploy local angular project on S3 bucket. Prerequisite: 1)Amazon web service account. You can get free tier account from amazon. 2)Build angular project and you have ready dist folder after build.  Command : ng build –prod Steps: After prerequisites are done you need to follow this steps, 1)Create an S3 bucket with public access. 2)After creating S3 bucket you need to upload files present inside dist folder of your angular project. In objects tab in S3 bucket there is upload option where you can add files. After adding files there will be option at bottom Predefined ACLs . Please grant public read access permission and then click on upload button at bottom. 3)Inside Properties tab at bottom you will see Static Web Hosting header. Inside that please check enable static website and at index document and error document please add value index.html. As your angular project after build in dist folder will have this file.                           

Node.js interview questions set 2

  Let start with set 2, 5)What is buffer in node.js? Ans:  Node.js includes an additional data type called Buffer (not available in browser's JavaScript).  Buffer is mainly used to store binary data while reading from a file or receiving packets over the network. Buffer class is a global class that can be accessed in an application without importing the buffer module. Ex:var buf = new Buffer(10); 6)Explain the concept of URL module in Node.js? Ans: The URL module in Node.js splits up a web address into readable parts.  Use require() to include the module: var url = require( 'url' ); Then parse an address with the url . parse() method, and it will return a URL object with each part of the address as properties . var url = require( 'url' ); var adr = 'http://localhost:8080/default.htm?year=2021&month=september' ; var q = url . parse(adr, true); console . log(q . host); // returns 'localhost:8080' console . log(q . pathname); // retur

Coding interview questions set 8

 Let's begin with set 8, 16)If given a max weight as input find out max allocation from a given array of jewelry weights. Example 1: Input: maxWeight=5 weightArray=[5,2,6] output: [{weight:5,qnt:1 }] Example 2: Input: maxWeight=12 weightArray=[5,2,6] output: [{weight:5,qnt:2},{weight:2,qnt:1}] Solution: function findCombination(maxWeight,weightArray) { var myArray = weightArray; let finalArray = []; for (let i = 0 ; i < myArray . length; i ++ ) { let effectiveWeight = myArray[i]; let remainder = maxWeight % effectiveWeight; let quotient = Math . trunc(maxWeight / effectiveWeight); if (quotient > 0 ) { finalArray . push({ weight: myArray[i], qnt: quotient }); } if (remainder == 0 ) { break ; } else { maxWeight = maxWeight - quotient * effectiveWeight; } } return finalArray; } Logic: Here we get quotient and remainder and p

Node.js interview questions set 1

  Let start with set 1, 1)error-first callback in node?  This question is asked many times don't know what special it is. Ans: The pattern used across all the asynchronous methods in Node.js is called Error-first Callback. Here is an example: fs.readFile( "file.json", function ( err, data ) {   if ( err ) {     console.error( err );   }   console.log( data ); }); Any asynchronous method expects one of the arguments to be a callback. The full callback argument list depends on the caller method,  but the first argument is always an error object or null.  When we go for the asynchronous method, an exception thrown during function execution cannot be detected in a try/catch statement. The event happens after the JavaScript engine leaves the try block. In the preceding example, if an exception is thrown during the reading of the file,  it lands on the callback function as the first and mandatory parameter. 2)What is a stub?  Ans: Stubs are functions/programs that simulate the