Home » Programming

Find/Replace Text in JavaScript with replace() [Examples]

JavaScript find/replace text

This quick tutorial will show you how to find and replace text in JavaScript, with code examples. Replacing text in strings is something you will probably need to do quite often. JavaScript comes with the replace() method as part of it’s String objects to handle this functionality. JavaScript Strings JavaScript Strings are a type of variable used to store and manipulate a sequence of characters. There are also string primitives which represent only the characters and do not contain methods for manipulation, but JavaScript will implicitly convert between the two when required. The … Read more

Home » Programming

The startsWith() Method for JavaScript Strings [Examples]

JavaScript startswith()

The startsWith() String method in JavaScript will determine whether a string starts with a certain string or character. Here’s how it is used, with code examples. startsWith() Method JavaScript Syntax The startsWith() method can be called from any String variable. string.startsWith(SEARCH, START) Note that: string can be any string value or variable SEARCH should be the string which you want to check if string starts with START is OPTIONAL If specified, START will be used as the starting position when checking STRING The portion of the string before START will be ignored This can be useful if you want to check whether a … Read more

Home » Programming

How to Get the Current Date and Time in JavaScript

JavaScript get current date/time

This article will show you how to get the current date, time, or both, in the JavaScript programming language. Code examples included. Date Objects in JavaScript Date objects represent a single point in time in JavaScript. They are created by initializing a new variable with a new Date object: var now = new Date(); By default, new Date objects are initialized to contain the date and time at the instant they were created, along with timezone details for the current device – thus representing the current … Read more

Home » Programming

Promises in JavaScript: What they Are, How to Use Them

JavaScript Promises

Promises are a feature of JavaScript which allow code to continue executing in the background, and perform an action with the result when it has completed. This article will show you how to use Promises. What is a ‘Promise’ in JavaScript? A Promise is an object in JavaScript which acts as a placeholder for the eventual result of an operation. A Promise is either: Pending while the operation completes Fulfilled when the operation is successful Rejected if the operation fails Promises allow for asynchronous code execution in JavaScript. … Read more

Home » Programming

How to Rename or Move a File/Folder/Directory in Python

Rename File or Folder/Directory in Python

This tutorial will explain how to rename or move a file or directory in the Python programming language and provide some simple examples you can follow. Looking to delete a file? Check out our tutorial on file/folder deletion in Python here. To Avoid Errors when Renaming, First Check if a File or Folder Exists To avoid errors when renaming or moving a file or folder, you should first check whether the path exists. The file which is to be moved or renamed must exist, and you … Read more

Home » Programming

How to Delete a File/Folder/Directory in Python

Delete a file or folder/directory in Python

This article will show you the various ways to delete files and directories in the Python programming language. To Avoid Errors, First Check if a File or Folder Exists To avoid errors when deleting a file, you can first check whether the file exists. You can also check whether Python is able to modify a directory. Deleting a File When a file has been confirmed to exist at a certain path, it can be deleted with the os.remove() function, which is part of the built-in Python os library which interacts … Read more

Home » Programming

Formatting Numbers with the JavaScript toFixed()* Method [Examples]

JavaScript toFixed()

This tutorial will show you how to format numbers to a fixed number of decimal places in the JavaScript programming language. JavaScript Number Variables JavaScript variables have different types. The type of a variable defines what kinds of values it can hold, and what can be done with that value. Number typed variables hold numeric values and include a number of methods (built in functions) for performing numeric operations. Number variables are declared by simply assigning a numeric value to a variable, or using the Number … Read more

Home » Programming

Checking an Array Contains a Value in JavaScript [Examples]

JavaScript in array includes

This article will show you how to check if a value is in an array in the JavaScript programming language. Code examples to check whether an array includes a value are provided. Arrays in JavaScript Arrays are a type of variable that hold an ordered list of values. Each value in an array has a position within the array, called the index. The index can be used to access each value in the array. Indexes are integer values, which start counting from 0 (zero) for the first … Read more

Home » Programming

Beginners Guide to Floating Point Arithmetic Precision

The Ultimate Beginners Guide to Floating Point Math/Arithmetic Precision Problems

This guide will explain the programming issues you will encounter when performing arithmetic with floating point numbers, and how to avoid them. The reason why these issues occur will be summarised and solutions will be provided. Floating point precision issues are common hurdle for beginner programmers – sometimes the result of what should be a simple mathematical operation comes out wrong, and little reason is given. Floating point precision issues are usually the cause, so here’s what they are and why this problem occurs. What … Read more

Home » Programming

Using The Python decimal Class for Accurate Calculations

Python decimal class

This guide will introduce you to the Python decimal library and class – Python tools which allow you to accurately work with decimal numbers without the rounding and accuracy issues which frequently arise when working with floating point numbers. Computers Can’t Perform Accurate Arithmetic With Decimal Numbers Decimal numbers are commonly stored as floating point number values. Computers are not particularly good at performing arithmetic with this type of numbers accurately. We break down why this is in our Ultimate Beginners Guide to Floating Point Math/Arithmetic Precision Problems. … Read more