Home » Programming » Javascript

Converting to Integer with JavaScript parseInt() [Examples]

JavaScript parseInt

This article will show you how to use the parseInt() function in the JavaScript programming language. JavaScript is notoriously loosely typed – meaning that variables of one type (e.g., strings of text, numerical values, boolean values) are converted to others, allowing you to perform mathematical operations on strings and silly things like that. This causes all sorts of issues – strings containing numbers may not be parsed to the expected value, and all of a sudden, you have angry clients wondering why your shiny new … Read more

Home » Programming » Javascript

The Difference Between JavaScript and Node.js – Which Should I Use?

JavaScript vs Node JS

This article explains JavaScript and Node.js and their relationship with each other. What is JavaScript? JavaScript has become one of the most popular programming languages for building web applications and has even become a contender for building solid desktop and mobile applications. In the browser, there is no competitor – browsers run JavaScript for their client-side code- allowing them to pop up windows, disable buttons, animate screen elements, and retrieve data. This is what JavaScript was built for. What is it Good For? JavaScript Runs … Read more

Home » Programming » Javascript

What is the ‘this’ Keyword in JavaScript (Object-Oriented Programming)

JavaScript 'this'

The ‘this‘ keyword in JavaScript is a confusing concept for some – the meaning of ‘this‘ changes based on context.  This article explains what ‘this‘ is. What is Object-Oriented Programming Object-Oriented Programming is a way of structuring your code so that data is organized into objects. JavaScript supports Object-Oriented programming and provides various tools to help implement it. Put simply, rather than having a bunch of separate abstract variables describing an item, you combine them into a single object which represents that item. You can also add functions … Read more

Home » Programming » Javascript

PHP vs JavaScript – The Best Choice For Your Project

PHP vs JavaScript

PHP and JavaScript are the most commonly used programming languages on the web – so which one should you use for your project? Check out our recent article on JavaScript vs. Node.js for another commonly searched programming comparison. Choosing which programming language to use for a project is important. Some of the questions you’ll want to run through are: Where will the application be run, and which languages are supported in that environment? Do I already have knowledge of one of the languages being considered? … Read more

Home » Programming » Javascript

Looping over Array using JavaScript forEach(), With Examples

JavaScript foreach

This article will show you how to use the JavaScript forEach() method to loop over an array. Pretty much any application of any complexity will require the looping over arrays (lists) of data. The JavaScript forEach() method, which is built into JavaScript array variables, does just this. You’ll be using it a lot – so thankfully, it’s pretty darn easy to use. JavaScript forEach() Syntax arr.forEach(callback(currentValue[, index[, array]]) { // execute something }[, thisArg]); Note that: arr is an array or a variable containing an array callback is the … Read more

Home » Programming » Javascript

TypeScript Vs JavaScript – What’s the Difference & Which Should You Use?

TypeScript Vs JavaScript

This article will discuss the differences between typescript and JavaScript, the problems they solve, and which is best to use. I really like TypeScript, and I use it a lot. It solves so many of JavaScript’s problems and makes writing good JavaScript code much easier (once you’ve learned to use TypeScript). So, this article is more about why you should use TypeScript (when you can use it), when/where you can use it, and the problems it solves. This article goes well with the following articles, giving you an … Read more

Home » Programming » Javascript

Add Days (or Minutes, or Hours) to Javascript Date [or Subtract]

Add Days to Javascript Date

This article will explain how to add (or subtract) days, minutes, hours, seconds (etc.) to a JavaScript date. Why would you want to do this? Perhaps you want to tell a user that their assignment is due in a week and provide the date, or maybe your application needs to know what the date was 30 days ago to pop up a reminder – there are near-infinite usage cases. Add Days to Date Using Vanilla JavaScript First, here’s how it’s done in plain old JavaScript: … Read more

Home » Programming » Javascript

Javascript eval() Function (and Why to NEVER Use It)

Javascript eval Function

The JavaScript eval() function executes a string as JavaScript. This is a massive security risk as, if used in production, it can allow third parties to execute their own code in your app. eval() Syntax eval(string) Note that: string is a string that contains JavaScript Code eval() will return the value returned by executing the code in the string Just don’t use it Example of Javascript eval() This article gets one example only so you can see how eval() works, so that if you accidentally fall on your keyboard and the … Read more

Home » Programming » Javascript

Assign Variables, Global Variables and Scopes in JavaScript (let, var, const)

JavaScript let var const

let, var, and const are all JavaScript statements that assign a value to a variable. Their behavior can differ depending on how and where they are used in your code – read on to find out the details. Scopes in JavaScript As you start to build more complex applications, you’ll start to see a lot of talk about scopes. A variable’s scope defines where it is available in your application. Global Scope (Global Variables) If a variable is in the global scope, it is available anywhere in your application. It can be called … Read more

Home » Programming » Javascript

Creating Multiline Strings in JavaScript [With Examples]

Creating Multiline Strings in JavaScript

There are several ways to create text that spans multiple lines in JavaScript – so here they are! Method 1: Backticks This is the best method, so it goes first. It is only compatible with ECMAScript 6 and onwards, so it is only for use in modern browsers (really, if you’re using any browser that isn’t Internet Explorer, you should be fine, but you should always test your code on the browsers you want to target). var multiText = ` This is multiline text!`; console.log(multiText) // … Read more