Category: JavaScript Basics
-
JavaScript String
The JavaScript string is an object that represents a sequence of characters. There are 2 ways to create string in JavaScript 1) By string literal The string literal is created using double quotes. The syntax of creating string using string literal is given below: Let’s see the simple example of creating string literal. Output: 2) By string…
-
JavaScript Functions
JavaScript functions are used to perform operations. We can call JavaScript function many times to reuse the code. Advantage of JavaScript function There are mainly two advantages of JavaScript functions. JavaScript Function Syntax The syntax of declaring function is given below. JavaScript Functions can have 0 or more arguments. JavaScript Function Example Let’s see the simple…
-
JavaScript Loops
The JavaScript loops are used to iterate the piece of code using for, while, do while or for-in loops. It makes the code compact. It is mostly used in array. There are four types of loops in JavaScript. 1) JavaScript For loop The JavaScript for loop iterates the elements for the fixed number of times. It should be used if number…
-
JavaScript Switch
The JavaScript switch statement is used to execute one code from multiple expressions. It is just like else if statement that we have learned in previous page. But it is convenient than if..else..if because it can be used with numbers, characters etc. The signature of JavaScript switch statement is given below. Let’s see the simple example of switch statement in…
-
JavaScript If-else
The JavaScript if-else statement is used to execute the code whether condition is true or false. There are three forms of if statement in JavaScript. JavaScript If statement It evaluates the content only if expression is true. The signature of JavaScript if statement is given below. Flowchart of JavaScript If statement Let’s see the simple example of if…
-
JavaScript Operators
JavaScript operators are symbols that are used to perform operations on operands. For example: Here, + is the arithmetic operator and = is the assignment operator. There are following types of operators in JavaScript. JavaScript Arithmetic Operators Arithmetic operators are used to perform arithmetic operations on the operands. The following operators are known as JavaScript…
-
Javascript Data Types
JavaScript provides different data types to hold different types of values. There are two types of data types in JavaScript. JavaScript is a dynamic type language, means you don’t need to specify type of the variable because it is dynamically used by JavaScript engine. You need to use var here to specify the data type. It can hold any type…
-
JavaScript Global Variable
A JavaScript global variable is declared outside the function or declared with window object. It can be accessed from any function. Let’s see the simple example of global variable in JavaScript Declaring JavaScript global variable within function To declare JavaScript global variables inside function, you need to use window object. For example: Now it can be declared inside…
-
JavaScript Variable
A JavaScript variable is simply a name of storage location. There are two types of variables in JavaScript : local variable and global variable. There are some rules while declaring a JavaScript variable (also known as identifiers). Correct JavaScript variables Incorrect JavaScript variables Example of JavaScript variable Let’s see a simple example of JavaScript variable. Output of…
-
JavaScript Comment
The JavaScript comments are meaningful way to deliver message. It is used to add information about the code, warnings or suggestions so that end user can easily interpret the code. The JavaScript comment is ignored by the JavaScript engine i.e. embedded in the browser. Advantages of JavaScript comments There are mainly two advantages of JavaScript comments. Types…