Home » Programming

Limit Column Values With The MySQL CHECK Constraint [Examples]

MySQL CHECK CONSTRAINT

This article will demonstrate the usage of the SQL CHECK Constraint to limit column values, as used in MySQL/MariaDB. The SQL CHECK constraint allows you to define limitations to the value which can appear in a table column. It also allows you to apply constraints to a whole table, letting you restrict a column’s values based on the values of other columns in the table row. This behavior is useful for making sure you are only getting valid data inserted into your database. For example, you might … Read more

Home » Programming

Default MySQL/MariaDB Port, Finding It, Changing It

Changing the MySQL Port

This article will show you how to find the default or current MySQL (or MariaDB) port and how to change it. What is a Port? A port is a numerical identifier for a communication endpoint on a computer network. Or, put simpler, it’s a unique number on your computer that points to a specific program that is running so that other programs can connect to it. MySQL/Maria DB, being networked database services, expose themselves to other computers via a configured port, allowing other computers to connect to and … Read more

Home » Programming

Beginners Guide: Create and Use JavaScript ES6 Modules

JavaScript Modules

This short tutorial aims to get you started creating and using JavaScript modules and provides some simple examples. What is ES6? JavaScript’s official name is actually ECMAScript, and version 6 introduced module functionality to create and consume modules, so you might see JavaScript Modules referred to as ES6 or ES2015 Modules. What is a JavaScript Module? As you get more adventurous with your JavaScript programming projects and your code becomes more complex, it might start to become harder to manage. One way of mitigating this is splitting … Read more

Home » Programming

Converting Variable Types in Python, Howto, With Examples

Python Type Conversion

This article will show you how to use Python’s built-in variable conversion functions, with examples. A variable’s type determines what kind of data it can store and what can be done with it. For example, string typed variables contain sequences of characters that can be joined and split (think words and sentences). In contrast, numeric typed variables contain numeric values intended to be used in calculations. Being able to convert a variable’s type allows data to be used in different ways. Converting a Variable to a … Read more

Home » Programming

Print an Array in PHP using print_r and var_dump, With Examples

PHP Print Array

This article will show you several methods on how to print an array in PHP, with some examples. Arrays in PHP can be processed using foreach loops to interact with each element in the array. This article focuses on directly printing an array in full rather than each element individually. Using echo to Print an Array (It Won’t Work) You might think that you can just use the echo statement to print an array in PHP – this is not the case, as seen below: <?php // Define an … Read more

Categories PHP

Home » Programming

Check Type of Variable in JavaScript with typeof [Examples]

JavaScript typeof Operator

This article will explain JavaScript variable types and how to find the type of a variable using the typeof operator. The typeof operator is quite similar to the instanceof operator – but they do not function the same way.  instanceof returns TRUE or FALSE when checking if a variable is of a certain type, whereas typeof returns the name of the type. What are Types? The type of a variable determines what it can or can’t do. It determines what value the variable may take and … Read more

Home » Programming

How to use the JavaScript trim Method, with Examples

JavaScript trim

This easy tutorial will show you how to use the JavaScript string trim() method and give some example usage. The trim()* method is available to any string type variable in JavaScript. It removes any white space (spaces, tabs, newlines) found at the beginning and the end of the string. Why is this useful? Sometimes you wind up with a bunch of un-needed white space padding your strings – often from the end-user hammering the space key when a space isn’t required. Unnecessary white space can also occur after splitting … Read more

Home » Programming

How to Get the Last Item in a JavaScript Array [Quick Tip]

JavaScript - Get last item in array

This quick article will show you how to get the last item in an array in the JavaScript programming language. Arrays and Array Indexes in JavaScript Arrays are an ordered list of items. Each item in the array has a numerical index that defines its permission in the array. The first index is index 0 (indexes start counting at 0, not 1!), so the last index is the array’s length; subtract 1. Getting the Last Item in an Array So, to get the last item in an array, we just … Read more

Home » Programming

How to Filter Arrays in JavaScript, With Examples

Javascript: filter arrays

We’ve covered arrays in JavaScript pretty extensively on LinuxScrew. This article will show you how to use the filter method – with easy-to-follow examples. JavaScript Arrays Arrays are a type of variable that holds a list of other values or variables. They’re one of the fundamentals of computer programming. These lists contain items at positions (called indexes). These items can be anything – numbers, strings, complex objects – whatever you want to store. Arrays are super useful. You might use them to store the rows in a … Read more

Home » Programming

How to Get the Length of an Array in JavaScript [Examples]

JavaScript Array Length

This article will show you how to get the length of an array in JavaScript, as well as provide some code examples. JavaScript is one of the most popular programming languages. From humble origins as a webpage scripting language for animating menus and displaying pop-up ads, it is now a full-blown ecosystem that you can use to build cross-platform mobile apps, web pages, server processes, and even games. JavaScript Arrays Arrays are a vital building block for any program, even simple ones. An array is a … Read more