Introduction to JavaScript

Introduction to JavaScript

ยท

4 min read

JavaScript is a versatile programming language used for web development. It enhances websites with dynamic and interactive elements, such as form validation, DOM manipulation, and animation. JavaScript is essential for modern web development and Its extensive library ecosystem and community support make it a top choice for modern web development. In this article, we will learn some basic fundamental concepts of JavaScript, Let's dive in and explore the exciting possibilities of JavaScript programming.

What is JavaScript ?

  • General-purpose & high-level programing language.

  • Single-threaded synchronous programing language.

  • Multi-paradigm programing language.

  • Prototype-based, object-oriented programing language

  • Just-in-time compiled programming language.

Identifiers and Keywords

  • Identifiers are names used to identify variables, functions, objects, or any other user-defined entity.

  • Keywords are similar to identifiers but it has some special meaning.

  • Keywords are the reserved words in a programming language.

  • It can't be used as a variable name and function name

e.g var, let, const, if, return, this, etc

Semicolon

  • Every Statement is terminated with a semicolon ;

  • It's optional to use.

Comment

  • It is used for documentation purposes and avoided by the compiler

  • Single-line comment

// This is a single-line comment
  • Multiple line comment
/*
This is a 
multi-line 
comment
*/

Output

  • It is the result of the program which is displayed to the user.

  • In JavaScript, There are several ways to print output.

    1. using console.log()

    2. using document.write()

    3. using alert()

1. Using Console.log()

  • It is a method used to output data or messages to the browser console.

  • The log() part of console.log() is a function call that accepts one or more arguments to be printed to the console.

  • The console. part of console.log() is an object reference that provides access to the log() method.

    Example

      console.log("Hello");
      console.log("Everyone");
    

    Output

      Hello
      Everyone
    

2. Using document.write()

  • It is a method used to write dynamic content to an HTML document.

Example

    <!DOCTYPE html>
    <html>
      <head>
        <title>Shubham Jha</title>
      </head>
      <body>
        <script>
          document.write("<h1>Hi Welcome </h1>");
        </script>
      </body>
    </html>

3. Using alert()

  • It is a method used to display output as a pop-up message.

Example

    alert("Hello, world!");

Input

  • Using the prompt() method, we can take user input.

  • It only takes a string as its argument.

Example

let name = prompt("What is your name?"); 
console.log("Hello, " + name + "!");

Output

What is your name?> Shubham
Hello, Shubham!

Values & Types

  • A Value represents a piece of data in JavaScript and different representations of value are called types.

    1. Number Types: A numerical value, such as 34, -6.14, 84

    2. Boolean Types: true and false

    3. String Types: "name"

    4. Undefined Types

    5. Null Types

    6. Symbol Types

    7. Object Types

Variables

  • A variable is a container that stores a value.

  • Two types of variables exist

    • Static Type: Values of fixed type are stored in a variable of fixed type.

    • Dynamic or Weak Type: Any type of value is stored in a variable.

  • JavaScript supports weak or dynamic typed variables, so we don't have to declare the type of variable, It can store any type of variable.

Variables Declare

  • Variables are created by using the let, const, or var keywords.

Example

var userName;
let age;

Variables Initialize

  • Assign the value to the variables

Example

var userName = "shubham";
let age = 18;

console.log(userName);
console.log(age);

Output

shubham
18

Variables Update

  • update the assigned value of the variable

    var and let can be updated

Example

var userName = "shubham";
console.log(userName);

userName = "developer";
console.log(userName);

Note

var can be updated and re-declared

let can be updated but not re-declared

Variable using const

  • It is used to declare a constant variable that cannot be reassigned.

  • It must be initialized with some value

  • It can't be updated or re-declared

Example

const userName = "shubham";
console.log(userName);

Happy Reading ! ๐Ÿ˜Š

ย