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:
Datatype | Description | Example |
Number | Numeric values can be real number or integers. | var x= number; |
String | Series of multiple characters written in quotes. | var x= “characters”; |
Boolean | Has only two values true or false. | var x= true/false; |
Null | Special value that represents that the variable is empty. | var x= null; |
Undefined | Represents a variable which is declared but not assigned any value. | let x; / let x= undefined; |
Object | Complex data type that allows us to store a collection of data. | var x= { key: “value”; key: “value”; } |
Array | Stores multiple values of same type in a single variable. | var x =[‘y1’, ‘y2′,’y3′,’y4’]; y: any datatype |
Function | Functions are objects that can be called to execute a block of code. | function x(arguments){ block of code } |
// 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.