My Experiments with JavaScript

Primitives 
1. String
2. Numbers 

  1. Whole Numbers or Integers
  2. Floating point numbers
3. Boolean
4. Null and undefined means there is no value.


BODMAS is the precedence of mathematical operations.
Bracket/Power/Division/Multiply/add/sub


"he said "hello" "
Use the following "he said \"hello\" "

Global scope - Any body from anywhere can access it  1. String is represented by quotes
Example : - "Madhu"



2. Determine the size of the String
"Madhu" length
O/P => 5

3. Use the prompt command to ask the user where they are from
prompt("What is your name?");

4. console.log() is used to write to the console


5. === represents equal to in JS

What is the difference between "==" and "===" in JS

== only compares values
=== compares values + type

var val1 = '178',
    val2 = 178;

val1 == val2 // true
val1 === val2 // false


6. If ... else

if (condition) 
{
    // if condition is true
    // do this code
}
else // "otherwise"
{
    // do this code instead
}

7. modulo. When % is placed between two numbers, the computer will divide the first number by the second, and then return theremainder of that division

8. substring () :- To get "Jan" from "January"
use :- "January".substring(0,3);

9. Variable declaration
var name = "Madhu";
comsole.log(name);

10 Function Declaration

var = function () {
      var nam = name;
      console.log(nam);
};

// Calling the function

11. Converting the first letter to Uppercase
var holeSection = "SURFACE";
holeSection.charAt(0).toUpperCase()+holeSection.substring(1, holeSection.length).toLowerCase()

Output : - Surface

12. A nicely written function 



var greeting = function (name) {
     console.log("Hello " +name);



greeting("Madhu");

13. For loop

for (var i = 1; i < 11; i = i + 1){
console.log(i);

}

14 Arrays
var arrayName = [data, data, data];
Embedded Arrays


15. The while loop is ideal when you want to use a loop, but you don't know how many times you'll have to execute that loop.

16. Switch case in javascript
var lunch = prompt("What do you want for lunch?","Type your lunch choice here");

switch(lunch){
  case 'sandwich':
    console.log("Sure thing! One sandwich, coming up.");
    break;
  case 'soup':
    console.log("Got it! Tomato's my favorite.");
    break;
  case 'salad':
    console.log("Sounds good! How about a caesar salad?");
    break;
  case 'pie':
    console.log("Pie's not a meal!");
    break;
  default:
    console.log("Huh! I'm not sure what " + lunch + " is. How does a sandwich sound?");

}
18 Object 
{} is the object lieral
var obj = {};
It has a key - value pairs
Key and value pair and if the key returns a primitive it is called a property
Key and value pair and if the value is a function then it is called method
obj = {name: "madhu"}
Object {name: "madhu"}
obj.name
"madhu"
obj[name]
undefined
var getProperty = "name";
undefined
obj[getProperty]

"madhu"

we can add/delete  properties anytime


prototype objects are the shared objects . JIT compiler looks at an object first and then look into prototype object.



No comments:

 Python Basics How to check the version of Python interpreter mac terminal

Popular in last 30 days