Posts

Featured Post

JavaScript - Implict null to number conversion

// null is 0 when used with number let num; num = 4 + null; console.log(num); // 4 num = 4 - null; console.log(num); // 4

JavaScript Implicit Boolean Conversion to Number

In Boolean true is 1, false is 0 let num; num = '4' - true; console.log(num); // 3 num = 4 + true; console.log(num); // 5 num = 4 + false; console.log(num); // 4

JavaScript implict conversion to number

You can implict convert a string to number using the following operators - , / , * let num; num = '6' - '4'; console.log(num); // 2 num = '4' - 2; console.log(num); // 2 num = '4' * 2; console.log(num); // 8 num = '4' / 2; console.log(num); // 2

JavaScript Implict Conversion to String

Implicit conversion is when JavaScript automatically converts one data type to another. let str; str = '1' + 2; console.log(str) // "12" str = '1' + true; console.log(str); // "1true" str = '1' + undefined; console.log(str); // "1undefined" str = '1' + null; console.log(str); // "1null"

Swapping array elements in JavaScript

Elements can be swapped using destructuring assignment expression var numbers = [1,2,3]; [numbers[2], numbers[1]] = [numbers[1], numbers[2]]; console.log(numbers); // [1,3,2] Without destructuring assignment, swapping two values requires a temporary variable

Ways to empty JavaScript array

There are different ways to empty an array in Javascript. By assigning an empty array var numbers =[1,3,5,6]; numbers =[]; By assigning array length to 0. var letters = ["a", "b", "c"]; letters.length = 0; By poping the elements of the array. var randomIntegers =[1,4,5,6]; while(randomIntegers.length > 0) { randomIntegers.pop(); } By using .splice() var cities =["Mumbai","Pune"]; cities.splice(0, cities.length)

Clone object in JavaScript

Object.assign() is a method which is used for cloning an object in JavaScript. Here is an example var person = { talk: "true" }; var male = Object.assign({}, person);

JavaScript variables cheatsheet

Here are some different ways by which you can create variables in JavaScript var a; // variable var b = "init"; // string var c = "Hi" + " " + "Joe"; // = "Hi Joe" var d = 1 + 2 + "3"; // = "33" var e = [2,3,5,8]; // array var f = false; // boolean var g = /()/; // RegEx var h = function(){}; // function object const PI = 3.14; // constant var a = 1, b = 2, c = a + b; // one line let z = 'zzz'; // block scope local variable

Delete Object property in Javascript

Image
You can remove properties from an object using the delete operator. The delete operator removed both the value and the property from the object.   Here is an example

ServiceNow Interview Questions

What is sys_id? Which protocal is used for create, update and delete incident through emails? How do you reference a Request Item's variable pool from any table? In a client script when should the call back option be used in 'getreference' How are workflows captured in update sets? How to flush out the servicenow instance chache? What are the few 'best practice' client side technologies that can speed up form speed without affecting performance? If you add a short description field to the task table? Does it also get added to child tables of the task table? When Using "g_form.getReference()" what is best practice? What would improve the performance of loading forms within ServiceNow? Can you call a business rule with the help of a client script? How Can You Cancel A Form Submission Through Client Script? What happens when a user make some changes to the homepage ? How you can remove Remember me check box from logi

Combine Python Lists

Combine Python Lists using plus(+) chars = ['a', 'b', 'c'] total_chars = chars + ['d', 'e'] print(total_items) # ['a', 'b', 'c', 'd', 'e'] Note: This approach not work for adding single item to the list, you can use .append(). Another approach to add one item is to create a new list with a single value and then use the plus symbol to add the list.

Pop from Python Dictionary

.pop() Method in Python We can use .pop() method to remove key-value pairs from Python dictionary. This method takes a key as an argument and removes it from the dictionary and it returns the value that it removed from the dictionary. user = {'first_name': 'nishant', 'last_name': 'nigam', 'city': 'Indore'} user.pop('city') print(user) # {'first_name': 'nishant', 'last_name': 'nigam'}

Merge dictionaries in Python

Merge dictionaries in Python with update() address = {'street': 'MG Road', 'house': '123'} contact = {'country': 'India', 'city': 'Indore', 'street': 'Ring Road'} address.update(contact) # Address dictionary will now have the updated data {'house': '123', 'country': 'India', 'city': 'Indore', 'street': 'Ring Road'} We can use update() when we are required to merge two dictionaries in Python address.update(contact), the key-value pairs of contact(dictionary2) will be written into the address(dictionary1).And for keys in both dictionary1 and dictionary2, the value in dictionary1 will be overwritten by the corresponding value in dictionary2

Remove falsy values from a JavaScript array using filter method

Here are examples of Falsy values (Falsy values returns false on evaluation) in JavaScript: undefined , null , NaN , 0 , "",  false We can use the JavaScript filter method to remove such values from our array var valueArray = ["Nishant", "IT", false, "India", 0, NaN, "JavaScript", undefined, null]; console . log ( valueArray . filter ( Boolean ) ); // returns ["Nishant", "IT", "India", "JavaScript"]