Posts

Namaste Javascript Study Notes -1

Image
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.

Image
 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

Image
  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

Image
 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

Image
  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

Rapid fire 28 javascript questions and answers .

Image
  Check these rapid javascript questions and answers that will help you to understand Javascript in a different way. Question 1: What is typeof [] ? Ans: Object. Actually, Array is derived from Object. If you want to check the array use Array.isArray(arr) Question 2: What is typeof arguments? Ans: Object. arguments are array-like but not array. it has length, can access by index but can't push pop, etc. Question 3: What is 2+true? Ans: 3. The plus operator between a number and a boolean or two boolean will convert boolean to number. Hence, true converts to 1 and you get a result of 2+1 Question 4: What is '6'+9 ? Ans: 69. If one of the operands of the plus (+) operator is a string it will convert other numbers or boolean to string and perform concatenation. For the same reason, "2"+true will return "2true" Question 5: What is the value of 4+3+2+"1" ? Ans: 91 . The addition starts from the left, 4+3 results 7 and 7+2 is 9. So far, the plus o

Mongodb Basics Set 1: Insert Operation

Image
  In this series, I would be sharing a few basic MongoDB articles on different operations. 1 )Insert a single record in MongoDB collection . var param = { firstname: "joey" , middlename: "" , lastname: "tribani" , phone: 9898989898 } db . collection( 'exampleset' ) . insertOne(param) This returns something like this: { "acknowledged" : true, "insertedId" : ObjectId( "56fc40f9d735c28df206d078" ) } You can also use 'insert' commond for inserting single record . db . collection( 'exampleset' ) . insert(param); This returns : WriteResult({ "nInserted" : 1 }); 2 )Insert multiple records in MongoDB collection . var records = [{ firstname: "joey" , middlename: "" , lastname: "tribani" , phone: 9898989898 },{firstname: "koey" , middlename: "" , lastname: "desuoiza" , phone: 9898989898