In this article, we are going to investigate what are the differences (and similarities) between JavaScript arrays and objects, and how do you know when to use objects vs arrays?
…
In this article, we are going to investigate what are the differences (and similarities) between JavaScript arrays and objects, and how do you know when to use objects vs arrays?
…
Maybe you have an issue with a server, which is sometimes returning either a JSON string with some useful data, and at other times server returns an error message string, which is produced by the PHP function mysql_error(). A simple solution to this problem would be to test whether this data is a JSON string or an error message.
A straightforward answer to a question on how to test if a string is JSON or not would be to use JSON.parse function isJson(str), like so:
function isJson(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
Nullish coalescing operator is a logical javascript operator that was introduced in JavaScript with the launch of ES2020 aka ES11and is symbolized with double question marks (??).
The nullish coalescing operator is a logical operator that accepts two operands – one on its left-hand side and one on its right-hand side and the syntax looks like this:
LeftHandSideOperand ?? RightHandSideOperand
Let’s see where we can use it.
…
In Javascript both var and let are used to declare a variable. However, there are a few differences between javascript var vs let, so let’s take a look at them.
…
Javascript language is de-facto standard for making client-side web applications that consume different kinds of APIs. It can even be used for mobile applications thanks to wrapper frameworks such as Apache Cordova, React Native, or NativeScript. You can even use it with gaming frameworks like Cocos 2D, Unity, or many others. Almost all games published in recent few years, especially for mobile phones can also be classified as client-side applications that interact with server-side sending and receiving data such as score, in-game positions, moves, and many others to the server through an API.
But let’s take a look at a simple example of Javascript client application that consumes an API using a built-in fetch function.
In Javascript we have a couple of options for checking equality, so let’s take a look at them – what are similarities, and what are the differences.
…
What is null in Javascript?
In JavaScript the value null represents the intentional absence of any object value. The value null is one of JavaScript’s primitive values and is treated as falsy for boolean operations. We could compare a value null to a similar primitive value – undefined. Undefined is an unintentional absence of any object value, and this “unintentional” is the thing that differentiates null from the undefined.
…
The beauty of PHP is that you can do one thing in several different ways. And, yes, this is the case with PHP arrays too – they can be merged using the + array union operator or you could use the array_merge() function. However, there is a difference between array_merge and array + array, so let’s take a look at the functions we’re are dealing with.
…
What if you are developing an application that requires a client to upload a file or an image and information about the image via RESTful API and you want the client to send data as JSON? The easy answer would be to perform two posts to REST API.
But is that even possible in a single request?
…