101.school
CoursesAbout
Search...⌘K
Generate a course with AI...

    JavaScript 101

    Receive aemail containing the next unit.
    • Introduction to JavaScript
      • 1.1What is JavaScript?
      • 1.2Setting up your environment
      • 1.3Basic syntax and variables
    • Data Types and Variables
      • 2.1Understanding data types
      • 2.2Variables and constants
      • 2.3Operators
    • Control Structures
      • 3.1Conditional statements
      • 3.2Loops
      • 3.3Error handling
    • Functions
      • 4.1Defining functions
      • 4.2Function expressions
      • 4.3Arrow functions
    • Objects and Arrays
      • 5.1Understanding objects
      • 5.2Understanding arrays
      • 5.3Array methods
    • Document Object Model (DOM)
      • 6.1What is the DOM?
      • 6.2Selecting and manipulating elements
      • 6.3Event handling
    • Asynchronous JavaScript
      • 7.1Callbacks
      • 7.2Promises
      • 7.3Async/Await
    • API Interaction
      • 8.1What is an API?
      • 8.2Fetch API
      • 8.3Working with JSON
    • Debugging
      • 9.1Console methods
      • 9.2Debugging tools
      • 9.3Common JavaScript errors
    • JavaScript Libraries
      • 10.1Introduction to libraries
      • 10.2Using jQuery
      • 10.3Using lodash
    • JavaScript Frameworks
      • 11.1Introduction to frameworks
      • 11.2Using React
      • 11.3Using Vue.js
    • Testing and Deployment
      • 12.1Writing tests with Jest
      • 12.2Deployment with Netlify
      • 12.3Continuous integration
    • Final Project
      • 13.1Project proposal
      • 13.2Project development
      • 13.3Project presentation

    Data Types and Variables

    Understanding JavaScript Data Types

    high-level programming language

    High-level programming language.

    In JavaScript, data types are the classifications we give to different kinds of data that we use in programming. In this article, we will explore the different data types in JavaScript and understand their characteristics.

    Introduction to JavaScript Data Types

    JavaScript is a dynamically typed language, which means that the same variable can be used to hold different data types. In JavaScript, there are two categories of data types: Primitive and Non-primitive.

    Primitive Data Types

    Primitive data types are the most basic data types in JavaScript. They include:

    String

    A string is a sequence of characters. In JavaScript, strings are enclosed within quotes. For example:

    let name = "John Doe";

    Number

    The Number data type is used to represent numeric values. It can be used to represent both integers and floating-point numbers. For example:

    let age = 30; let weight = 72.5;

    Boolean

    The Boolean data type can hold only two values: true or false. It is typically used to store values like yes (true) or no (false), on (true) or off (false), etc.

    let isAdult = true;

    Null

    The Null data type has only one value: null. It represents a reference that points to a nonexistent or invalid object or address.

    let empty = null;

    Undefined

    A variable that has not been assigned a value is of type undefined.

    let test; console.log(test); // Output: undefined

    Symbol

    Introduced in ES6, a symbol is a unique and immutable data type that is often used as an identifier for object properties.

    let symbol1 = Symbol('symbol');

    Non-primitive Data Types

    The non-primitive data types are Objects. An object is a collection of properties, and a property is an association between a name (or key) and a value.

    let person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};

    Differences Between Primitive and Non-primitive Data Types

    The main difference between primitive and non-primitive data types is that primitive data types store values directly, while non-primitive data types store references to the values.

    Type Coercion and Conversion

    JavaScript is a loosely typed language, which means it automatically converts types as needed during the execution of the program. This is known as type coercion. For example, when you try to add a number and a string, JavaScript will convert the number to a string before performing the operation.

    let result = 5 + "7"; // Output: "57"

    In conclusion, understanding data types in JavaScript is fundamental to being able to write effective code. Each data type has its own set of behaviors and capabilities, and knowing these can help you choose the right data type for the task at hand.

    Test me
    Practical exercise
    Further reading

    Hey there, any questions I can help with?

    Sign in to chat
    Next up: Variables and constants