Skip to main content


Css Interview Questions Set 1

Let's begin with set 1, 1)What is CSS box model? The CSS box model is essentially a box that wraps around every HTML element. It consists of: margins, borders, padding, and the actual content. The image below illustrates the box model: Explanation: Content - The content of the box, where text and images appear. Padding - Clears an area around the content. The padding is transparent Border - A border that goes around the padding and content. Margin - Clears an area outside the border. The margin is transparent. 2)What are selectors in CSS? In CSS, selectors are patterns used to select the elements you want to style. Here are few most used selectors, a).class : Ex:.intro Selects all elements with class="intro". b).class1.class2 Ex: .name1.name2 Selects all elements with both name1 and name2 set within its class attribute. c)#id  Ex:#firstname Selects the element with id="firstname". d)element  Ex:p Selects all <p> ele

Coding Interview Questions Set 2

For first 3 questions and answers please refer to   Coding Interview Questions Set 1 . Let's begin with set 2, 4)For a given binary tree find the depth/height of a binary tree. Solution : var depth= function(root) {     if(root === undefined || root===null){         return 0;     }     return Math.max(depth(root.left),depth(root.right)) + 1; }; Logic: Divide and conquer. 5)In a given array move all the 0 's to the end without disturbing order of non-zero elements.  Solution: var moveZeroes = function(nums) {          for(var i = nums.length;i--;){         if(nums[i]===0){             nums.splice(i,1)             nums.push(0);         }     } }; Logic: Remove each 0 and add 0 at the end of the array. 6)Calculate the sum of 2 integers without using + and - operator. Solution: var add = function(a, b) {     let carry;     while(b) {         carry = a & b;         a ^= b;         b = carry << 1;     }     return a; }; Logic:

Coding Interview Questions Set 1

From this article, I will be sharing with you all a series of articles on coding interview questions. So please stay connected for the latest set of questions. It will be a good brainstorming exercise and will also prepare you for coding interviews and will definitely boost your confidence. So let's start, 1)Reverse of a string with only O(1) extra memory. Solution: var reverse = function(string) {     let result = ''     for(let i= string.length -1; i >= 0; i--){         result += string[i];     }     return result; }; 2)Fizz Buzz: Write a program that will accept a number n and will output number till n but for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”. Solution: var fizzBuzz= function(n) {     const arr=[]     for(i=1; i<=n; i++){         if(i%15===0) arr.push("FizzBuzz")         else

Node.js: Downloading a xml file from given url and reading its data elements.

In this article, we will see how we can download an XML file from a given URL and then access its elements. This can be used in many cases, for example, scraping data from a site which has data in the XML file or multiple files. The article is pretty short and most of it is just self-explanatory code. Also nowadays, you can get a lot of freelance jobs in data scrapping as data is the new oil today so this might be helpful. So let's begin with the code, var fs = require('fs') var https = require('https');//For accessing https url we need this module instead of http. var xml2js = require('xml2js');//Required for xml parsing. var file_name = 'data.xml'//This will be the name of file we will be generating. var DOWNLOAD_DIR =__dirname+'/'; //This function reads data from URL and writes data into new file //with respect to the given name and directory path. function download(){  var file_url='

2 JavaScript Interview Questions that you must know.

In this article, we will see in detail a couple of interview questions in Javascript. 1)What is a deep copy and Shallow copy? Shallow copy:  In shallow copy, all the top-level primitives get a copy excluding objects which are still connected to the original value. Note: If the array is of strings or number it gets copied but in case of an array of objects it is still connected to the original value. Primitive data types include the following: Number — e.g. 1 String — e.g. 'Hello' Boolean — e.g. true undefined null Example: var tshirt={     size:170,     sizeInLocal:'L',     sizeAvailable:{     'm':"Available"      } } Lets make a copy a shallow copy of tshirt object: var tshirt1=Object.assign({}, tshirt) tshirt1.sizeAvailable.m="NotAvailable"//Here tshirt.sizeAvailable.m will also become NotAvailable . tshirt1.size=150;//Only value of tshirt1.size is changed and not tshirt.size as size is of primitive type.  

4 html interview questions that you must know.

In this article, we will see some HTML interview questions I faced during interviews. So let's start, 1)What is Doctype in html? All HTML documents must start with a <!DOCTYPE> declaration. The declaration is not an HTML tag. It is an "information" to the browser about what document type to expect. In HTML 5, the declaration is simple: <!DOCTYPE html> Note: The <!DOCTYPE> declaration is NOT case sensitive. 2)What is DOM in html? The DOM (Document Object Model)is a W3C (World Wide Web Consortium) standard. The DOM defines a standard for accessing documents: The HTML DOM is a standard object model and programming interface for HTML. When a web page is loaded, the browser creates a Document Object Model of the page. It defines: The HTML elements as objects The properties of all HTML elements The methods to access all HTML elements The events for all HTML elements In other words: The HTML DOM is a standard for how to get, chan

Javascript/Node.js: 2 Features that you might not know.

This is a very short article where we will be discussing two Javascript features that you may not know. Also, you may like this article about two new Node.js features.    So let's start, 1)Exponentiation operator(**): This operator was added in ES6 and is supported by most of the browsers but excluding internet explorer. It is also called an Infix operator for Exponentiation. Before for exponentiation, we have to use Math.pow(x,y). But now you can use x**y. For example: 2**5 //returns 32 2)Numeric Separators: Large numeric literals are difficult for the human eye to parse quickly, especially when there are lots of repeating digits. To improve readability, you can use underscores as separators in numeric literals. For example: let value= 100_000_000_00 //Is same as 10000000000 As of May 2020, It is supported by all major browsers (Chrome[75+], Firefox[70+], Edge, Safari[13+], Opera) ( source 1 , source 2 for more details about differe