Cristian Salcescu's Blog, page 12

April 19, 2021

How to Remove a Property From an Object in JavaScript

How to Remove a Property From an Object in JavaScript

An object is a dynamic collection of key-value pairs. Here is such an object.

const dto = {
message : 'Hi',
priority: 1
}

A property can be deleted using the delete operator.

When the property key is a valid identifier we can use the dot notation to access and delete the property.

delete dto.priority;console.log(dto);
//{message: "Hi"}

When the key is stored in a variable we can use the bracket notation to access and delete the property. Consider t...

 •  0 comments  •  flag
Share on Twitter
Published on April 19, 2021 03:46

April 18, 2021

How to Check If a Property Is Not Null

Using optional chaining and the Boolean function to test for falsy values

Continue reading on Frontend Essentials »

 •  0 comments  •  flag
Share on Twitter
Published on April 18, 2021 23:15

April 16, 2021

How to Repeat a String in JavaScript

How to Repeat a String in JavaScript

Here are two ways to create a string repeating a specific text in JavaScript.

repeat()

The simplest way to create a new string repeating a text is to use the repeat() string method.

The repeat() method returns a new string containing the specified number of copies of the given text.

Below is an example.

'Apple'.repeat(3);
//AppleAppleApple

fill()

There is also an old way of achieving the same result by first creating an array of the needed size, fill in the default va...

 •  0 comments  •  flag
Share on Twitter
Published on April 16, 2021 04:19

How to Convert Values into Strings in JavaScript

The String built-in function, the toString method, and more

Continue reading on Frontend Essentials »

 •  0 comments  •  flag
Share on Twitter
Published on April 16, 2021 00:47

April 15, 2021

How to Jump Values in The Array Destructuring

How to Jump Values in The Array Destructuring

To skip a value when using the array destructuring assignment syntax we just leave it blank and put a comma after it.

Here is an example of destructuring out the second and third values of an array.

const [,b,c] = [1, 2, 3, 4, 5];
console.log(b);
//2
console.log(c);
//3

Below is an example of extracting out only the third value of the array.

const [,,c] = ['A', 'B', 'C'];
console.log(c);
//'C'

Here is an example of destructuring out the third value from a comma-...

 •  0 comments  •  flag
Share on Twitter
Published on April 15, 2021 03:04

April 14, 2021

7 Common JavaScript Bugs You Can Now Avoid

Functions with the same name, inexact decimal arithmetic, creating callbacks in loops, losing this context, and more

Continue reading on Better Programming »

 •  0 comments  •  flag
Share on Twitter
Published on April 14, 2021 08:52

April 13, 2021

How to Know If an Array Has Duplicates in JavaScript

Set collections, equality for objects, the map array method, and more

Continue reading on Frontend Essentials »

 •  0 comments  •  flag
Share on Twitter
Published on April 13, 2021 00:02

How to Know if an Array Has Duplicates in JavaScript

Set collections, equality for objects, the map array method, and more

Continue reading on Frontend Essentials »

 •  0 comments  •  flag
Share on Twitter
Published on April 13, 2021 00:02

April 12, 2021

How to Create and Delete a Git Branch

Some of the basic things we may need to do when working on a feature are to create a development branch and then delete that branch after merging the changes.

Here is how we can do that.

Creating a local branch

Below is an example of creating a new branch new-dev-branch from the master branch.

git checkout -b new-dev-branch masterCreating a remote branch

Creating a local branch does not mean that a branch is also created in the remote repository. There is a new command for that.

git push -u origin new...
 •  0 comments  •  flag
Share on Twitter
Published on April 12, 2021 00:47

April 11, 2021

How to Know If an Array is Not Empty in JavaScript

This short post shows how to check the size of an array and verify if it is not empty.

Continue reading on Frontend Essentials »

 •  0 comments  •  flag
Share on Twitter
Published on April 11, 2021 08:17