Datatypes

There are different types of datatypes that can be stored in JavaScript variables. For the machine to be able to operate on variables, and correctly evaluate the expressions it is important to know about the type of variables involved. There are following primitive and non-primitive datatypes in JavaScript:

DatatypeDescriptionExample
NumberNumeric values can be real number or integers.var x= number;
StringSeries of multiple characters written in quotes.var x= “characters”;
BooleanHas only two values true or false.var x= true/false;
NullSpecial value that represents that the variable is empty.var x= null;
UndefinedRepresents a variable which is declared but not assigned any value.let x; / let x= undefined;
ObjectComplex data type that allows us to store a collection of data.var x= {
    key: “value”;
    key: “value”;
}
ArrayStores multiple values of same type in a single variable.

var x =[‘y1’, ‘y2′,’y3′,’y4’];

y: any datatype

FunctionFunctions are objects that can be called to execute a block of code.

function x(arguments){

    block of code

}

JavaScript
// String
let str = "hello geeks";
console.log(str);

// Number
const num = 10;
console.log(num);

// Boolean
const x = "true";
console.log(x);

// Undefined
let name;
console.log(name );

// Null
const number = null;
console.log(number);

// Symbol
const value1 = Symbol("hello");
const value2 = Symbol("hello");
console.log(value1);
console.log(value2);

// Here both values are different 
// as they are symbol type which 
// is immutable object
const object = {
    firstName: "geek",
    lastName: null,
    batch: 2,
};
console.log(object);

JavaScript Cheat Sheet – A Basic Guide to JavaScript

JavaScript is a lightweight, open, and cross-platform programming language. It is omnipresent in modern development and is used by programmers across the world to create dynamic and interactive web content like applications and browsers. It is one of the core technologies of the World Wide Web, alongside HTML and CSS, and the powerhouse behind the rapidly evolving Internet by helping create beautiful and crazy-fast websites.

This article provides an in-depth JavaScript Cheat Sheet, a must-have for every web developer.

JavaScript Chear Sheet

Similar Reads

What is JavaScript Cheat Sheet?

Our comprehensive JavaScript Cheat Sheet is designed to assist both beginners and experienced coders in mastering this versatile programming language. Whether you’re building interactive web pages, creating dynamic content, or enhancing user experiences, this quick reference guide provides essential concepts, syntax, and ready-to-use code snippets....

Fundamentals

To use JavaScript on website we need to attach the JavaScript file to the HTML file. To do a better code, we should also do the commenting during the code. There are two types of commenting single-line and multiline....

Variables

Variables in JavaScript are containers for storing data. JavaScript allows the usage of variables in the following three ways:...

Datatypes

There are different types of datatypes that can be stored in JavaScript variables. For the machine to be able to operate on variables, and correctly evaluate the expressions it is important to know about the type of variables involved. There are following primitive and non-primitive datatypes in JavaScript:...

Operators

JavaScript operators are symbols used to perform various operations on variables (operands). Following are the different types of operators:...

JS scope and scope chain

Scope: Scope defines the accessibility or visibility of variables in JavaScript. That is, which sections of the program can access a given variable and where the variable can be seen. There are usually three types of scopes.Scope chain: The scope chain is used to resolve the value of variable names in JavaScript. Without a scope chain, the JavaScript engine wouldn’t know which value to pick for a certain variable name if there are multiply defined at different scopes. If the JavaScript engine could not find the variable in the current scope, it will look into the outer scope and will continue to do so until it finds the variable or reaches the global scope. If it still could not find the variable, it will either implicitly declare the variable in the global scope (if not in strict mode) or return an error....

Functions

A JavaScript function is a block of code designed to perform a particular task. It is executed when invoked or called. Instead of writing the same piece of code again and again you can put it in a function and invoke the function when required. JavaScript function can be created using the functions keyword. Some of the functions in JavaScript are:...

Arrays

In JavaScript, array is a single variable that is used to store different elements. It is often used when we want to store list of elements and access them by a single variable. Arrays use numbers as index to access its “elements”.Declaration of an Array: There are basically two ways to declare an array....

Loops

Loops are a useful feature in most programming languages. With loops you can evaluate a set of instructions/functions repeatedly until certain condition is reached. They let you run code blocks as many times as you like with different values while some condition is true. Loops can be created in the following ways in JavaScript:...

If-else

If-else is used in JavaScript to execute a block of codes conditionally. These are used to set conditions for your code block to run. If certain condition is satisfied certain code block is executed otherwise else code block is executed. JavaScript allows us to nest if statements within if statements as well. i.e, we can place an if statement inside another if statement....

Strings

Strings in JavaScript are primitive and immutable data types used for storing and manipulating text data which can be zero or more characters consisting of letters, numbers or symbols. JavaScript provides a lot of methods to manipulate strings. Some most used ones are:...

Regular Expressions

A regular expression is a sequence of characters that forms a search pattern. The search pattern can be used for text search and text to replace operations. A regular expression can be a single character or a more complicated pattern....

Data Transformation

Data transformation is converts data from one format to another. It can be done with the usage of higher-order functions which can accept one or more functions as inputs and return a function as the result. All higher-order functions that take a function as input are map(), filter(), and reduce()....

Date objects

The Date object is an inbuilt datatype of JavaScript language. It is used to deal with and change dates and times. There are four different way to declare a date, the basic things is that the date objects are created by the new Date() operator.Syntax:...

DOM

DOM stands for Document Object Model. It defines the logical structure of documents and the way a document is accessed and manipulated. JavaScript can not understand the tags in HTML document but can understand objects in DOM.Below are some of the methods provided by JavaScript to manipulate these nodes and their attributes in the DOM:...

Numbers and Math

JavaScript provides various properties and methods to deal with Numbers and Maths....

Events

Javascript has events to provide a dynamic interface to a webpage. When a user or browser manipulates the page events occur. These events are hooked to elements in the Document Object Model(DOM). Some of the events supported by JavaScript:...

Error

When executing JavaScript code, errors will most definitely occur when the JavaScript engine encounters a syntactically invalid code. These errors can occur due to the fault from the programmer’s side or the input is wrong or even if there is a problem with the logic of the program. Javascript has a few statements to deal with these errors:...

Window Properties

The window object is the topmost object of DOM hierarchy. Whenever a window appears on the screen to display the contents of document, the window object is created. To access the properties of the window object, you will specify object name followed by a period symbol (.) and the property name....

Benefits of Using JavaScript Cheat Sheet

A JavaScript Cheat Sheet is an essential tool that simplifies the process of writing JavaScript code, helps your web applications function smoothly, and enables you to create interactive and dynamic web content....