Here we started the tutorial with Variables, Operator.
|What’s inside: |
- The Script tag in the <head>…</head> section.
- Script in <body>…</body> section.
- The Script tag in <body>…</body> and <head>…</head> sections.
- Script tag in an external file and then include in <head>…</head> section.
If you know any programming languages, then you are familiar with this word. The variables can be thought of as named containers. You can place the data into these containers and then refer to the data by merely naming the container.
The variable of JS is a “named storage” for data. We can use variables to store different data like goodies, visitors, and other data. It should be declared only once, and repeated declaration of the same variable is an error.
Var is the keyword for declaring a variable.
‘=’Is the operator to assign a value to a variable.
- The variable must start with _ or $ or letter. 99temp is an invalid type, whereas _99temp is a suitable type of declaration.
- In ES2015 (ECMAscript), there are two different ways to declare introduced variables- let and const. We can use these two keywords to define variables(now recommended).
If you want to concatenate the string description of two variables’ values, use the + sign:
var val1='' Tom''; var val2='' jerry''; var val3= var1+var2;
Try-it-out – 1
Try-it-out – 2
F = (9 * C/5) + 32
var c=30; var F=(9*c/5)+32; console.log("Fahrenheit temp. is "+ F);
At first, we have to know that What is an Operator? The simple expression 5 + 5 is equal to 10. Here 5 and 5 are they called operands, and ‘+’ is called the operator.
- Assignment operators
- Arithmetic operators
- Comparison operators
- Logical operators
- String operators
- Conditional operators
- The most programming languages = is the assignment operator.
- The Variables can be declared either by key var and value OR simply by assigning values directly. Ex – var x = 43; OR x = 43 ;
- An explicit type declaration is not necessary.
- The same variable can be put values of different data types. To know the kind of a variable, use the kind of operator.
var x = "hello"; var x = true; console.log(typeof x); //returns Boolean
- The == compares the operands and returns true without considering their data type. Ex: var a = 10, b= “10”;
- If the (a==b) results are accurate due to the same value, they carry but ignores data types differentiation.
- However, if the (a===b) results are false as they are of different data types.
Standard Arithmetic Operators
|%||Modulus (Division Remainder)|
- Addition + Ex: [5 + 8]
- Subtraction – Ex: [49 – 38]
- Division / Ex: [ 49 / 7]
- Multiplication * Ex: [28 * 2]
More on Arithmetic Operators
- The Modulus % to return the remainder of a division – Ex: 50 % 7 is 1
- Increment ++ to increment the operand itself by 1 – Ex: If x=4, x++ evaluates to 5
- The Decrement — to decrement the operand itself by 1 – Ex: if x= 10, x—- evaluates to 9
Expr1 && Expr2 returns true if both are true, else returns false.
Expr1 || Expr2 returns true if either is true.
- The !Expr1 operates on a single operand to convert true to false and vice versa.
The string operator is zero or more characters written inside quotes. You can also use the quotes inside a string, but always remember they should not match the string quotes:
var answer1 = "It's alright"; var answer2 = "He is called 'Joe'"; var answer3 = 'He is called "Josh"';
The Operator + is used to concatenate strings. x = “Hello”; y = ” World “; x + y; /* Returns “Hello World” *
The length of property returns the length of a string:
Output of the following code:
The length property of JS returns the length of a string=
1. Is the given assignment a valid variable assignment? var product cost = 3.45;
Ans: No, there would be no space between the variable name.
Ans: Towards the end of the body to increase the performance of the webpage
3. What is true about variables?
Answer:- Variables are case sensitive
4. What is the value of C? var a = 100; var b = “10”; var c = a + b;
Please stay with us on this journey :).
Really needed this kind of easy yet detailed post.
Keep it up..doing great stuf
Great stuff. Keep it up.
Great ❤️ keep it up more
I like this content because it is clear and very summarised for the beginner. I will refer my students here. Thanks for the content.