<commit_before>/* Operators used for performing any operation in a programming language
Javascript has arithmetic, assignment, comparison, logical, bitwise and
unary operators among others */

var num = 0;

// Arithmetic Operators

num = num + 2;
num = num * 3;
num = num / 2;
num++;
num--;

console.log(num);

// Assignment Operators

num += 1;
num -= 2;
num *= 3;
num /= 2;
num %= 3;

console.log(num);

// Comparison Operators

/* the identity operator (===) behaves identically to the equality operator (==)
except no type conversion is done, and the types must be the same to be considered
equal.

The equality operator (==) will compare for equality after doing any necessary
type conversions. For example 1 == '1' would yield true, for example. The
identity operator will not do type conversion at all, 1 === '1' would yield
false.  Try to use identity operators instead of equality operators. */

console.log('num == 1 : ' + (num == 1));
console.log('num === 1 : ' + (num === 1));
console.log('num != 1 : ' + (num != 1));
console.log('num > 1 : ' + (num > 1));
console.log('num < 1 : ' + (num < 1));
console.log('num >= 1 : ' + (num >= 1));
console.log('num <= 1 : ' + (num <= 1));

// Logical Operators

console.log('true && false : ' + (true && false));
console.log('true || false : ' + (true || false));
console.log('!true : ' + (!true));

// Bitwise Operators

console.log('5 & 1:', (5 & 1));
console.log('5 | 1:', (5 | 1));
console.log('~ 5:', (~5));
console.log('5 ^ 1:', (5 ^ 1));
console.log('5 << 1:', (5 << 1));
console.log('5 >> 1:', (5 >> 1));

// typeof vs instanceof

var num = 1;
var price = 1.5;
var name = 'Chris';
var trueValue = true;
var nullVar = null
var und;

console.log('typeof num:', typeof num);
console.log('typeof price:', typeof price);
console.log('typeof name:', typeof name);
console.log('typeof trueValue:', typeof trueValue);
console.log('typeof nullVar:', typeof nullVar);
console.log('typeof und:', typeof und);
console.log('typeof [1,2,3]:', typeof [1,2,3]);

// Delete Operators

var myObj = {name: 'John', age:21};
delete myObj.age;
console.log(myObj);<commit_msg>create function testTruthy to see what boolean different values would return<commit_after>/* Operators used for performing any operation in a programming language
Javascript has arithmetic, assignment, comparison, logical, bitwise and
unary operators among others */

var num = 0;

// Arithmetic Operators

num = num + 2;
num = num * 3;
num = num / 2;
num++;
num--;

console.log(num);

// Assignment Operators

num += 1;
num -= 2;
num *= 3;
num /= 2;
num %= 3;

console.log(num);

// Comparison Operators

/* the identity operator (===) behaves identically to the equality operator (==)
except no type conversion is done, and the types must be the same to be considered
equal.

The equality operator (==) will compare for equality after doing any necessary
type conversions. For example 1 == '1' would yield true, for example. The
identity operator will not do type conversion at all, 1 === '1' would yield
false.  Try to use identity operators instead of equality operators. */

console.log('num == 1 : ' + (num == 1));
console.log('num === 1 : ' + (num === 1));
console.log('num != 1 : ' + (num != 1));
console.log('num > 1 : ' + (num > 1));
console.log('num < 1 : ' + (num < 1));
console.log('num >= 1 : ' + (num >= 1));
console.log('num <= 1 : ' + (num <= 1));

// Logical Operators

console.log('true && false : ' + (true && false));
console.log('true || false : ' + (true || false));
console.log('!true : ' + (!true));

// Bitwise Operators

console.log('5 & 1:', (5 & 1));
console.log('5 | 1:', (5 | 1));
console.log('~ 5:', (~5));
console.log('5 ^ 1:', (5 ^ 1));
console.log('5 << 1:', (5 << 1));
console.log('5 >> 1:', (5 >> 1));

// typeof vs instanceof

var num = 1;
var price = 1.5;
var name = 'Chris';
var trueValue = true;
var nullVar = null
var und;

console.log('typeof num:', typeof num);
console.log('typeof price:', typeof price);
console.log('typeof name:', typeof name);
console.log('typeof trueValue:', typeof trueValue);
console.log('typeof nullVar:', typeof nullVar);
console.log('typeof und:', typeof und);
console.log('typeof [1,2,3]:', typeof [1,2,3]);

// Delete Operators

var myObj = {name: 'John', age:21};
delete myObj.age;
console.log(myObj);

// Truthy vs Falsy

/*Undefined and null both return false
-For booleans, true returns true false returns false
-for numbers, -0,+0 or NaN return false, otherwise result is true
-for strings, result is false if the string is empty, otherwise true
-objects result in true

*/

function testTruthy(val) {
  return val ? console.log('truthy') : console.log('falsy');
}

testTruthy(true);
testTruthy(false);

// But when create a Boolean object, objects are always true
testTruthy(new Boolean(false));

var test = new Boolean(false);
console.log(typeof test);

testTruthy('');
testTruthy('Chris');
testTruthy(new String(''));
testTruthy(1);
testTruthy(-1);
testTruthy(NaN);
testTruthy(new Number(NaN));
testTruthy({});

var obj = {name:'John'};
testTruthy(obj);
testTruthy(obj.name);
testTruthy(obj.age);
//age does not exist
{'fraction_non_alphanumeric': 0.18003913894324852, 'fraction_numerical': 0.02426614481409002, 'mean_word_length': 4.247433264887063, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2481194', 'n_tokens_mistral': 1778, 'n_tokens_neox': 1679, 'n_words': 599}