Skip to content

Instantly share code, notes, and snippets.

@sasknot
Last active November 3, 2021 20:16
Show Gist options
  • Save sasknot/5e20230675a06dfef2fd to your computer and use it in GitHub Desktop.
Save sasknot/5e20230675a06dfef2fd to your computer and use it in GitHub Desktop.
Javascript basics

Primary Data Types

  • String
  • Number
  • Boolean

Composite Data Types

  • Object
  • Array

Special Data Types

  • Null
  • Undefined

Keywords

break		else		new 		var		case
finally		return		void		catch		for
switch		while		continue	function	this
with		default		if		throw		delete
in		try		do		instanceof	typeof

Reserved words

abstract	enum		int		short		boolean
export		interface	static		byte		extends
long		super		char		final		native
synchronized	class		float		package		throws
const		goto		private		transient	debugger
implements	protected	volatile	double		import
public

Typical reserved words

alert		eval		location	open		array
focus		math		outerHeight	blur		function
name		parent		boolean		history		navigator
parseFloat	date		image		number		regExp
document	isNaN		object		status		escape
length		onLoad		string

Conversions

To string

* Undefined   "undefined"
* Null        "null"
* Boolean     If **true**, then "true"; if false, then "false"
* Number      The string representation of the number, or **NaN** if the variable holds this latter value
* Object      A string representation of the default representation of the object

To boolean

* Undefined   **false**
* Null        **false**
* Number      **false** if number is 0 or **NaN**; otherwise, **true**
* String      **false** if string is empty; otherwise, **true**
* Object      true

To number

* Undefined   NaN
* Null        0 (IE returns **NaN**)
* Boolean     If **true**, the result is 1; otherwise, 0 (IE returns **NaN**)
* Number      Straight value
* String      Integer or float, depending on representation
* Object      NaN

Comparsion

* undefined == null    true
* undefined == true    false
* undefined == false   false
* undefined == 0       false
* undefined == ''      false
* undefined == {}      false
* undefined == []      false

* null == true    false
* null == false		false
* null == 0       false
* null == ''      false
* null == {}      false
* null == []      false

* 0 == ''     true
* 0 == {}     false
* 0 == []     true		

* '' == {}    false
* '' == []		true

* {} == []    false

Evaluation

* undefined   false
* null        false
* ''          false
* 0           false
* {}          true
* []          true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment