JavaScript Statements: Understanding the Basics for Developers

JavaScript Statements are an essential part of programming in JavaScript. While expressions are single units that the engine can evaluate, statements are made up of different expressions and are executed by the engine to perform operations. In this blog post, we will explore the different types of JavaScript statements and how they are used. Separating Statements JavaScript statements can be written on a single line or span multiple lines. Each statement can end with an optional semicolon ;, although it is not always necessary....

JavaScript Symbols: Explained and Utilized

Symbols are a unique and powerful data type in JavaScript, introduced in ECMAScript 2015. Unlike other primitive data types like strings, numbers, booleans, null, and undefined, symbols have a distinct characteristic - their values are kept private and meant for internal use only. Once created, symbols are immutable and their values remain hidden, with only the symbol reference accessible. To create a symbol, you can use the Symbol() global factory function....

JavaScript Ternary Operator

In this blog, we will explore the fundamentals of the JavaScript Ternary Operator and understand how it can be used as a concise way to express conditionals. The ternary operator is a unique operator in JavaScript that works with three operands. It offers a compact syntax to evaluate conditions and choose between alternative expressions. The syntax of the ternary operator is as follows: <condition> ? <expression> : <expression> The <condition> is evaluated as a boolean value....

JavaScript Type Conversions: A Guide

Learn the fundamentals of JavaScript type conversions Even though JavaScript is a loosely typed language, there may arise situations where you need to convert a value from one type to another. In JavaScript, we have primitive types like numbers, strings, booleans, and symbols, along with the object type. However, converting from or to null and undefined is not necessary. Here are some common conversion scenarios and techniques to achieve them:...

JavaScript Typecasting: Converting Data Types

Learn how to convert data types in JavaScript In JavaScript, although it is a loosely typed language, there may be instances where you need to convert values from one type to another. JavaScript has these primitive types: Number String Boolean Symbol and the object type: Object (plus null and undefined, but there’s no point in casting from/to them) Let’s explore different techniques for converting from one type to another. We’ll cover the most common scenarios....

JavaScript typeof Operator

In JavaScript, every value has an assigned type. To determine the type of a variable, we can use the typeof operator, which returns a string representing the variable’s type. Here are a few examples of using the typeof operator: typeof 1; //'number' typeof '1'; //'string' typeof {name: 'Flavio'}; //'object' typeof [1, 2, 3]; //'object' typeof true; //'boolean' typeof undefined; //'undefined' typeof (() => {}); //'function' typeof Symbol(); //'symbol' It’s interesting to note that JavaScript doesn’t have a specific “function” type....

JavaScript Variables: A Complete Guide

Introduction to JavaScript Variables In JavaScript, variables are used to store and reference values in a program. Unlike other programming languages, JavaScript variables do not have any type attached to them. This means that once you assign a value to a variable, you can reassign it to a different type without any type errors or issues. This feature is what makes JavaScript “untyped.” Declaring Variables with var Before ES2015 (also known as ES5), the var keyword was the only way to declare variables in JavaScript....

JavaScript vs Python: Which Language to Choose for Beginners?

People often ask me which programming language they should start with: JavaScript or Python. As a senior developer and author of books on both JavaScript and Python, I can tell you that both languages are great options for beginners and extremely popular in the industry. However, there are certain differences between them that can help you make an informed decision. JavaScript, being the language of the web, has a significant advantage in frontend development....

JavaScript: How to Get a Substring Until a Specific Character

In JavaScript, there are several ways to extract a substring from a string until a specific character is encountered. This can be useful when you want to retrieve the first part of a string before a certain delimiter, such as a hyphen ("-"). One simple approach is to use the split() method, which splits a string into an array of substrings based on a specified delimiter. By specifying the hyphen as the delimiter, we can extract the desired substring by accessing the first element of the resulting array....

JavaScript: How to Get the Class Name of an Object

If you have an object that is generated from a class and you want to retrieve its class name, there are a couple of ways you can do so. Let’s explore these techniques. Suppose you have an object that is generated from a class called Dog. You want to get the class name of this object. Here’s an example code snippet: class Dog { // Class implementation } const roger = new Dog(); In this case, roger is the object that is created from the Dog class....