Show Menu
Cheatography

Javascript is a scripting language which is used to interaction

01 . Into to javasc­rtipt

• Js is a plAnd it allows developers to add dynamic and intera­ctive effects to any webpage.

• We also use it to manipulate the content or the CSS, load data from remote servers ,and really build entire applic­ations in the browser,

• There has been a huge update to the language in 2015, which is officially called ES2015, but most people just call it ES6,

Condit­ional operator

syntax: condition:true statement : false statement

const age = 88;
age >= 18 ? console.log("you can") :console.log("you wont ");

Template literals

const firstname = "Sathiya";
const firstname1 = "SathiyaPriyan";
const $new = 
${firstname} is a  guy  
; console.log($new);
Template literals - use varible in a string , use multiple line is easy

p1-use stright mode

"use strict­";


-> Use certian things and visible errors

-> and like that write more secure code. And when secure, I mean that strict mode
makes it easier for us developers to avoid accidental error

Array methods

// Adds

push - add an element in a end
unshift(): Adds elements to the beginning of an array.

//Remove

pop - remove last element of an array
shift(): Removes and returns the first element of an array.

//Find index

indexOf(): Returns the index of the first occurrence of a specified element ; minus value mean does not exit

//Check array exit or not

includ­es(): Checks if an array contains a specified element. - immutable
 

Link js file

<script src="index.js"></script>
Link from another page , Script in same page simple use script tag

Value and variable

Camal case

Type Conversion and Coercion

nan - not a valid number or not a number
Js - convert only string , boolen , number not other type

True valuse and false value

5 falsy values in js

0,'',u­nde­fined , null , nan

Version of javascript

p2-Fun­ction declar­ation and expression

"use strict";

// Function declaration

function calAge1(birthYear) {
  const age = 2029 - birthYear;
  return age;
}
console.log(calAge1(2003));

// Anonymous function - expressions is a vaule
const me = function (birthYear) {
  const age = 2029 - birthYear;
  return age;
};

Object

// and it's called the object literal Syntax

const spObject = {
  firstName: "sathiya",
  lastName: "sp",
  age: 27,
  destinitation: "student",
  habits: ["productivity", "time management"],
};
In arrays there is no way of giving these elements a name. And so we can't reference them by name, but only by their order number in which they appear in the array.

So we solve that problem we have another data structure in JavaSc­ript, which is object

object is for unstru­ctured data
array is for ordered data
 

3 ways iof declaring a javascript

let , const is a modern way of declaring variable var is a old way of declarig of js
------­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­-----
let age = 0 // Varaibale declare
age = 1 // it is a mutated variable or reasign variable
------­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­-----
let vs const -> const is a best practice .
The reason for this is that it's a good practice
to have as little variable mutations or variable changes as possible because changing variables introduces a potential bug
------­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­---­-----
var is completely avoid
or declare nothing - bad practice

Equality operator

The strict equality operator (
===
) compares two values without type coercion

while the loose equality operator (
==
) compares values with type coercion in JavaSc­ript.is full of really weird rules and behaviors. this can introduce many hard
to find bugs into our code. clean code

Versio­n-pic-2

p3-Arrow functions

syntax : let func = (arg1, arg2, ..., argN) => expression

It is introuded in ES6 vesrion

Javascript dot vs bracket

Put into any via loops

const yearsfa = [1991, 2007, 1967, 2020];

const age = [];
const newArray = [];
function calAge($var) {
  return 2023 - $var;
}
for (let count = 0; count <= years.length; count++) {
  console.log((age[count] = calAge(years[count])));
  newArray.push(age);
}
console.log("--");
console.log(newArray);

console.log(calAge(2003));
for (let count = 0; count < array.length; count++) {
  const element = array[count];
}
 

To check what kind of data type

typeof

Data types

NULL is undefined data type

operator

Check c notes
Operator precedence So basically the order in which operators are executed.

Get input from webpage

const $colour = prompt(`Tell your 
most favourate colour`);

console.log($colour);

Versio­n-pic-3

Calling function inside another functions

function cutFruit(fruit) {
  return fruit * 4;
}

function fruitProcessor(apples, oranges) {
  const appleP = cutFruit(apples);
  const orangesP = cutFruit(oranges);
  const juice = 
Juice with ${apples} apples and ${oranges} oranges
;   return juice; }
       
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

            Bootstrap Glyphicons Cheat Sheet by James Croft
          Five ways to center DIV element in CSS Cheat Sheet