Javascript fundamentals

Javascript fundamentals

Code structure

  1. Semicolon

    In javascript, we can write code repeatedly. Javascript separate each code with a semicolon (;) :

     console.log("Javascript"); console.log("Fundamentals");
    

    We can also don't use semicolons. If we don't use semicolons we must write code line by line. Like this:

     console.log("Javascript")
     console.log("Fundamentals")
    
  2. Comment line

    When we write code, our code is being read by others. (By the way, there is a well-known saying that well-written code doesn't need comment. The code must be entirely understandable). If we write any javascript code in the comment line it will not work. Because it's in the comment line. In Javascript two types of comment lines. First, if we want to put a comment for one line we can use two brackets (//) after our comment:

     // Javascript is easy
     console.log(5-1);
    

    If we want to put two lines or more comments we must use slash and stars (/**/). For open comment area write / after * and for close comment area write * after / :

     /* This is two lines comment.
     There is could be more comments
     let a=5;
      */
     console.log(Math.floor(18.3965));
    

Variables

In computer programming, a variable is an abstract storage location paired with an associated symbolic name, which contains some known or unknown quantity of information referred to as a value; or in simpler terms, a variable is a named container for a particular set of bits or type of data (like integer, float, string, etc...). A variable can eventually be associated with or identified by a memory address. The variable name is the usual way to reference the stored value, in addition to referring to the variable itself, depending on the context. This separation of name and content allows the name to be used independently of the exact information it represents. The identifier in computer source code can be bound to a value during run time, and the value of the variable may thus change during the course of program execution.

Declaration variable

When declaring a variable we don't need to write variable type. Because Javascript is an interpreter language. Javascript automatically knows what type is the variable. We just write the variable name and its value.

name="Bob"; // Javascript know that variable type is String
age=35; // Number
admin=false; // Boolean

In Javascript have three declaration keywords. let, var and const.

  1. let keyword allows you to declare variables that are limited to the scope of a block statement, or expression on which it is used

  2. var keyword declares a function-scoped or globally-scoped variable, optionally initializing it to a value.

  3. const keyword creates block-scoped constants, much like variables declared using the let keyword. The value of a constant can't be changed through reassignment (i.e. by using the assignment operator), and it can't be redeclared (i.e. through a variable declaration)

TO BE CONTINUED...