Skip to main content

"A Simple Explanation : Data Types and Operators"


Data Types


JavaScript has several built-in data types, which are used to represent different kinds of values. 

 Undefined: It means that a variable has been declared but doesn't have a value yet. 

 Null: It represents the intentional absence of any value. 

 Boolean: It has only two values, either "true" or "false". It's used for making decisions. 

 Number: It represents any numeric value, like whole numbers or decimals. 

 String: It represents a sequence of characters, like words or sentences. It is enclosed in quotes. 

 Symbol: It's a unique and immutable value often used as a special identifier.

 Object: It's a collection of properties and methods, like a container that holds related information. Array: It's a list of values stored in a specific order. 

 Function: It's a reusable block of code that performs a specific task. 

 Remember, these are the basic data types, and JavaScript allows you to use them in combination or transform them as needed.


Operators


JavaScript provides a variety of operators that allow you to perform operations on values and variables. 

Operators allow you to perform various computations, comparisons, and logical operations to manipulate and work with values in your JavaScript code.

Here are some of the most commonly used operators in JavaScript:


Arithmetic Operators: Used for mathematical calculations.

Addition: +

Subtraction: -

Multiplication: *

Division: /

Remainder (Modulus): %

Exponentiation: **


Assignment Operators: Used to assign values to variables.

Assignment: =

Addition assignment: +=

Subtraction assignment: -=

Multiplication assignment: *=

Division assignment: /=

Remainder assignment: %=


Comparison Operators: Used to compare values and return a boolean result.

Equal to: ==

Not equal to: !=

Strict equal to: ===

Strict not equal to: !==

Greater than: >

Less than: <

Greater than or equal to: >=

Less than or equal to: <=


Logical Operators: Used to combine or negate logical expressions.

Logical AND: &&

Logical OR: ||

Logical NOT: !


Increment/Decrement Operators: Used to increase or decrease the value of a variable.

Increment: ++

Decrement: --


String Operators: Used for string concatenation.

Concatenation: +


Ternary Operator: A shorthand way to write conditional statements.

Ternary operator: condition ? expression1 : expression2


Typeof Operator: Used to determine the type of a value.

Typeof operator: typeof


Member Access Operators: Used to access properties or methods of objects.

Dot notation: object.property

Bracket notation: object['property']


These are a few examples of the operators available in JavaScript:

Example 1:

                                let a = 5;

                                let b = 3;

                                let c = 8;

                                let result = (a + b) * c - (a % b);

                                console.log(result);

 

Example 2:

let age = 20;

let isAdult = age >= 18 ? "Adult" : "Minor";

console.log(isAdult); 

 Output: "Adult"






Comments

Popular posts from this blog

"All about Variables"

 "In the realm of JavaScript's code, Variables hold a powerful mode." In JavaScript, variables are used to store data values.  Variable Declaration: In JavaScript, you can declare variables using the var, let, or const keywords. Already discussed in the previous blog (  Link to it  ). 1. Variable Naming: Variables can have a wide range of names, but they must follow certain rules: They can contain letters, digits, underscores, or the dollar sign. The first character must be a letter, an underscore, or a dollar sign. Variables are case-sensitive (myVariable and myvariable are considered different variables). It's a good practice to use descriptive names that reflect the purpose of the variable. JavaScript has a set of reserved keywords that have predefined meanings and cannot be used as identifiers (such as variable names or function names) in your code. 2. Variable Assignment: You can assign a value to a variable using the assignment operator (=). The assigned value c

"From LiveScript to JavaScript: The Evolution of a Dynamic Programming Language"

  The Evolution of JavaScript JavaScript is a programming language that was created in the mid-1990s to make websites more interactive and dynamic. It allows developers to add functionality to web pages and create things like pop-up messages, form validation, and interactive elements.   JavaScript started with basic features but evolved over time, adding new capabilities and becoming more powerful.   Initially, different web browsers had their own versions of JavaScript, which caused compatibility issues. However, the language eventually became standardized under the name ECMAScript. Different versions of ECMAScript introduced new features and improvements to make JavaScript more versatile and easier to use. Birth of JavaScript:   In 1995, Netscape, a prominent web browser at the time, wanted to add a scripting language to enhance the interactivity of web pages. Brendan Eich, a Netscape employee, was tasked with creating such a language.   He developed a prototype in just ten days, ini

"A Beginner's Guide to the Fundamentals"

  How to run JavaScript code? To write JavaScript code using Visual Studio Code (VSCode), follow these steps: 1. Install Visual Studio Code: Download and install Visual Studio Code from the official website: https://code.visualstudio.com/ 2. Set Up a Project Folder: Create a folder on your computer where you'll store your JavaScript files. Open Visual Studio Code and select "Open Folder" to open your project folder. 3. Create a JavaScript File: Inside your project folder, right-click and choose "New File" to create a new file. Give the file a name with the .js extension (e.g., index.js). 4.Write JavaScript Code: Open the JavaScript file in Visual Studio Code. Start writing your JavaScript code in the file. 5. Running JavaScript Code: To execute the JavaScript code, you have a few options: Open the integrated terminal in Visual Studio Code using Ctrl+ (backtick) and runnode script.js` to run the script using Node.js. Install Node.js from here To print "Hello