Basic Concept of javaScript
JavaScript is a multi-paradigm, dynamic language with types and operators, standard built-in objects, and methods. JavaScript supports object-oriented programming with object prototypes, JavaScript also supports functional programming — because they are objects, functions may be stored in variables and passed around like any other object.
JavaScript is a powerful programing language. Nowadays knowledge about JavaScript is must necessary for being a good programmer or developer.
Today I will discuss some JavaScript Basics Concept.
Variable
JavaScript variables are containers for storing data values.
In this example,
x
,y
, andz
, are variables, declared with thevar
keyword:
Example
var x = 5;
var y = 6;
var z = x + y;
Using let and const (ES6)
Before 2015, using the var
keyword was the only way to declare a JavaScript variable.
The 2015 version of JavaScript (ES6) allows the use of the const
keyword to define a variable that cannot be reassigned, and the let
keyword to define a variable with restricted scope.
Because it is a little complicated to describe the difference between these keywords, and because they are not supported in older browsers, the first part of this tutorial will most often use
var
.
variables may hold values that have different data types:
This is a sequence of text known as a string. To signify that the value is a string, enclose it in single quote marks.
let myVariable = ‘Bob’;
This is a number. Numbers don’t have quotes around them.
let myVariable = 10;
This is a True/False value. The words true and false are special keywords that don’t need quote marks.
let myVariable = true;
This is a structure that allows you to store multiple values in a single reference.
let myVariable = [1,’Bob’,’Steve’,10];
Refer to each member of the array like this:
myVariable[0], myVariable[1], etc.This can be anything. Everything in JavaScript is an object and can be stored in a variable. Keep this in mind as you learn.
let myVariable = document.querySelector(‘h1’);
All of the above examples too.
Comments
/*
Everything in between is a comment.
*/
If your comment contains no line breaks, it’s an option to put it behind two slashes like this:
// This is a comment
Operator
An operator
is a mathematical symbol that produces a result based on two values (or variables). In the following below, you can see some of the simplest operators, along with some examples to try in the JavaScript console.
Addition
Add two numbers together or combine two strings.
+
6 + 9;
‘Hello ‘ + ‘world!’;Subtraction, Multiplication, Division
These do what you’d expect them to do in basic math.
-, *, /
9–3;
8 * 2; // multiply in JS is an asterisk
9 / 3;Assignment
As you’ve seen already: this assigns a value to a variable.
=
let myVariable = ‘Bob’;
Equality
This performs a test to see if two values are equal. It returns a true/false (Boolean) result.
===
let myVariable = 3;
myVariable === 4;Not, Does-not-equal
This returns the logically opposite value of what it precedes. It turns a true into a false, etc.. When it is used alongside the Equality operator, the negation operator tests whether two values are not equal.
!, !==
For “Not”, the basic expression is true, but the comparison returns false because we negate it:
let myVariable = 3;
!(myVariable === 3);“Does-not-equal” gives basically the same result with different syntax. Here we are testing “is myVariable NOT equal to 3”. This returns false because myVariable IS equal to 3:
let myVariable = 3;
myVariable !== 3;