Code Monkey home page Code Monkey logo

new-frontend-labs's Introduction

JavaScript CheatSheet

Copyright (c)2023 Promineo Tech
Promineo Tech Academic Team

Variable Declaration:

	var x = "value";
	let y = "value";
	const z = "value"; (constant, can not be changed)

Data Types:

• Number (e.g. 42)
• String (e.g. "Goodbye World")
• Boolean ( e.g. true/false)
• Undefined (e.g. undefined)
• Null (e.g. null)
• Object (e.g. {})
• Array (e.g. [1,2,3,4,5])

Arrays:

• Create: 
	var arr = [element1, element2, element3];
• Access: 
	arr[index];
• Update: 
	arr[index] = newElement;
• Methods: 
		 arr.push(element)
		 arr.pop()
		 arr.shift()
		 arr.unshift(element)
		 arr.slice(start, end)
		 arr.splice(index, deleteCount, element)

Operators:

• Arithmetic: +, •, *, /, % (modulo)
• Assignment: =, +=, •=, *=, /=, %=
• Comparison: ==, ===, !=, !==, >, <, >=, <=
• Logical: &&, ||, !

Control Flow:

if•else:

	if (condition) { 
		statements; 
	} else {
		statements;
	}

switch:

	switch (expression) { 
		case x: statements; 
		        break; 
		case y: statements; 
		        break; 
		default: statements; 
	}

for loop:

	for (var i = 0; i < 10; i++) { 
		statements; 
	}

while loop:

	while (condition) {
		statements;
	}

do•while loop:

	do {
		statements;	
	} while (condition);

Functions:

• Define: 
	function name(param1, param2) { statements; }
• Call: 
	name(arg1, arg2);
• Arrow function: 
	(param1, param2) => { statements; }

Objects

• Create: 
	var obj = { key1: value1, key2: value2 };
• Access: 
	obj.key1 or obj["key1"]
• Update: 
	obj.key1 = newValue;

Event Handling:

• element.addEventListener("eventType", function() { statements; });
	button.addEventListener("click", function() { alert("Button clicked!"); });

DOM Manipulation

• Get element: 
	document.getElementById("id"), document.querySelector("css selector")
• Change content: 
	element.innerHTML = "new content";
• Change style: 
	element.style.property = "new value";

String Methods

• length: 
	str.length
• concatenate: 
	str1 + str2
• indexOf: 
	str.indexOf("substring")
• slice: 
	str.slice(start, end)
• replace: 
	str.replace("old", "new")

new-frontend-labs's People

Contributors

conwaycj avatar cmrapp avatar sw-dev-lisa-s-nh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.