+ All Categories
Home > Technology > Javascript cheatsheet

Javascript cheatsheet

Date post: 18-Mar-2018
Category:
Upload: andrea-tino
View: 200 times
Download: 6 times
Share this document with a friend
1
Variables & types Flow control Functions Javascript basics Andrea Tino This document uses graphic assets from Freepik var name = init-value ; var name ; Variables are used to store values and retrieve them later. They are essential building blocks in every program you will ever write. Javascript supports very basic types: strings and numbers. var str = “hello”; var integer = 10; var decimal = 1.5; var num1 = 1/2; var num2 = num1*2; var myvar = 0; console.log(myvar); code if ( condition ) { } Javascript is a programming language very simple but extremely powerful. It is used by browsers today so that web pages can be interactive and very dynamic. In your favorite browser’s window, hit F12 and bring up the Developer Tools. You can write some Javascript in the console tab to have some fun. Sometimes you ant certain code to be executed, but not always. Conditionals are used to execute code only when one or more conditions are met. Loops (or cycles) are used everytime you want to execute the same code many times. code for (var i=0; i< n ; i++) { } if (1 < 2) { alert(”Hi!”); } for (var i=0; i<10; i++) { console.log(”This is:” + i); } What if you have a piece of code you end up executing many times in different parts of your code? Functions help you modularize and reuse pieces of code that you execute very often in your program. code function name ( args ) { } A function must first be declared: function-name ( args ); Then a function can be invoked: function greetMe (name) { alert(”Hello ” + name); } greetMe (”Batman”);
Transcript
Page 1: Javascript cheatsheet

Variables & types

Flow control

Functions

Javascript basics Andrea Tino

This document uses graphic assets from Freepik

var name = init-value ;var name ;

Variables are used to store values and retrieve them later. They are essential building blocks in every program you will ever write.

Javascript supports very basic types: strings and numbers.

var str = “hello”;var integer = 10;var decimal = 1.5;var num1 = 1/2;var num2 = num1*2;

var myvar = 0;console.log(myvar);

codeif ( condition ) {

}

Javascript is a programming language very simple but extremely powerful. It is used by browsers today so that web pages can be interactive and very dynamic.

In your favorite browser’s window, hit F12 and bring up the Developer Tools. You can write some Javascript in the console tab to have some fun.

Sometimes you ant certain code to be executed, but not always. Conditionals are used to execute code only when one or more conditions are met.

Loops (or cycles) are used everytime you want to execute the same code many times. code

for (var i=0; i< n ; i++) {

}

if (1 < 2) { alert(”Hi!”);}

for (var i=0; i<10; i++) { console.log(”This is:” + i);}

What if you have a piece of code you end up executing many times in different parts of your code?Functions help you modularize and reuse pieces of code that you execute very often in your program.

codefunction name ( args ) {

}

A function must first be declared:

function-name ( args );

Then a function can be invoked:

function greetMe (name) { alert(”Hello ” + name);}

greetMe (”Batman”);

Recommended