Consider an object: var user = { name: “Jagathish”, age: 20} In the user object, the name and age are the keys of the object. Keys are also referred to as object “properties”. We can access the property value by obj.propertyName or obj[propertyName]. The Object.keys() method returns an array of strings of a given object’s …
Tag Archives: javascript
Five Ways to Reverse an Array in Javascript
We can reverse an array by both modifying the source array or without modifying the source array. We will look at different ways to do each. Reversing an array by modifying the source array We can use the reverse method available to JavaScript arrays. var numbers = [ ‘1️⃣’ , ‘2️⃣’, ‘3️⃣’, ‘4️⃣’, ‘5️⃣’ ];numbers.reverse();console.log(numbers); // …
Continue reading “Five Ways to Reverse an Array in Javascript”
Ternary operator in Javascript
Learn about how and when to use ternary operator in Javascript Ternary operator in Javascript Ternary operator is also denoted as conditional operator. Ternary operator is the compact version of if statement. If you’re going to check for simple condition, then ternary operator is highly recommended instead of if block. Example of using normal if …
Default Parameters in Javascript
Learn about how and when to use default parameters in Javascript. default param Default parameter in Javascript The default parameter is a way to set default values for function parameters a value is no passed in (ie. it is undefined). In a function, Ii a parameter is not provided, then its value becomes undefined. In …
var vs let & const in Javascript.
The Key Difference var is function scoped.let and const is block scoped. Let’s see what this means. Function Scope Function scope means if we declare a variable with the var keyword then the variable is accessible for the lifetime of the function inside the entire function in which it is declared. Example: function test() { …
Secrets of Logical ️ Operators in Javascript 🤷
Learn how logical operators in Javascript is different from other programming languages (&& || !) Logical operations allow us to make decisions (either true or false ), based on conditions. In most programming languages, the logical operation returns either true or false. In Javascript, logical operations return the value of one of the operands used in …
Continue reading “Secrets of Logical ️ Operators in Javascript 🤷”
Everything you need to know about error handling in Javascript
Exception handling is the way that we can prevent abnormal program termination on runtime due to some Exception. For example In the above case, instead of termination of the program, we can handle it by try…catch block. Any error inside try block doesn’t cause program termination. If an error is caused inside the try block …
Continue reading “Everything you need to know about error handling in Javascript”
A short introduction to CSS variables
Using CSS variables we can set a value to a property and reuse it in our CSS code. This can be thought of almost exactly how we use variables in JavaScript. When do we need CSS variables? When we are working on a project, and we need to use the same value (text color, background, …
Converting a string to camelCase in Javascript
Learn how to convert a string into camelCase in Javascript. image from wikipedia camelCase: Camel case (stylized as camelCase; also known as camel caps or more formally as medial capitals) is the practice of writing phrases such that each word or abbreviation in the middle of the phrase begins with a capital letter, with no …
Continue reading “Converting a string to camelCase in Javascript”
First class Function in Javascript.
Learn about what is first class function and how to use it , in Javascript. A programming language is said to support First class function , if A function can be assigned to a variable, 2. A function can be passed as an argument, 3. A function can be returned from other function. A function can be …