DEV Community

Raisul Islam Rabby
Raisul Islam Rabby

Posted on

Tricky things of javascript

Truthy
In JavaScript, a truthy value is a value that is considered true when encountered in a Boolean context. All values are truthy unless they are defined as falsy (i.e., except for false, 0, -0, 0n, "", null, undefined, and NaN).
Falsy
A falsy (sometimes written falsey) value is a value that is considered false when encountered in a Boolean context.
Difference between call,apply and bind
Call( ): The call() method invokes a function with a given 'this' value and arguments provided one by one. This means that we can call any function, and explicitly specify what 'this' should reference within the calling function.
Apply( ): Invokes the function and allows you to pass in arguments as an array.
Bind(): returns a new function, allowing you to pass in an array and any number of arguments.
setTimeout()
As we said before, setTimeout() executes a particular block of code once after a specified time has elapsed. It takes the following parameters:
A function to run, or a reference to a function defined elsewhere.
A number representing the time interval in milliseconds (1000 milliseconds equals 1 second) to wait before executing the code. If you specify a value of 0 (or omit the value), the function will run as soon as possible. (See the note below on why it runs "as soon as possible" and not "immediately".) More on why you might want to do this later.
Zero or more values that represent any parameters you want to pass to the function when it is run.

setInterval()
setTimeout() works perfectly when you need to run code once after a set period of time. But what happens when you need to run the code over and over again-for example, in the case of an animation?
This is where setInterval() comes in. This works in a very similar way to setTimeout(), except that the function you pass as the first parameter is executed repeatedly at no less than the number of milliseconds given by the second parameter apart, rather than once. You can also pass any parameters required by the function being executed as subsequent parameters of the setInterval() call.
What is an API?
An API (Application Programming Interface) is a set of functions that allows applications to access data and interact with external software components, operating systems, or microservices.
To simplify, an API delivers a user response to a system and sends the system's response back to a user. You click "add to cart;" an API tells the site you added a product to your cart; the website puts the product in your cart, and your cart is updated.
What is JSON and why is it used?

What is an API? A Digestible Definition with API Examples for Ecommerce Owners
GET THE PRINT VERSION
Tired of scrolling? Download a PDF version for easier offline reading and sharing with coworkers.
DOWNLOAD PDF
You've probably heard the terms API, Public API, or Web API before. These are often used by software companies when speaking about an application, operating system or website. They are used everywhere in today's world and offer a tremendous benefit. But have you ever wondered what an API actually is, or how to use it?
What is an API?

An API (Application Programming Interface) is a set of functions that allows applications to access data and interact with external software components, operating systems, or microservices.
To simplify, an API delivers a user response to a system and sends the system's response back to a user. You click "add to cart;" an API tells the site you added a product to your cart; the website puts the product in your cart, and your cart is updated.
You may hear the term "microservices" come up in relation to API. These however, are not the same. Microservices are a style or architecture which divides functionality within a web application. While API is the framework which developers interact with a web application. Microservices can actually use API to communicate between each other.
API lets a developer make a specific "call" or "request" in order to send or receive information. This communication is done using a programming language called "JSON." It can also be used to make a defined action such as updating or deleting data. There are four basic request methods that can be made with API:
GET - Gathers information (Pulling all Coupon Codes)
PUT - Updates pieces of data (Updating Product pricing)
POST - Creates (Creating a new Product Category)
DELETE - (Deleting a blog post)

So What is JSON and why is it used?

JSON (JavaScript Object Notation) is used to represent data on a server. It's fairly easy to read by humans, and easy for machines/applications to understand. Let's look at an example of JSON from a product on BigCommerce:
What is an API Request?
There are several components of an API Request in order for it to function. Let's go over these individually and how they can be used to build a request.

Latest comments (0)